9th
"Object is not missing <ClassName>!" + Amazon::S3
Today at the office, we had one of the weirdest Rails errors I have ever encountered
rails-project/vendor/rails/activesupport/lib/active_support/dependencies.rb:417:in `load_missing_constant’: Object is not missing constant Photo! (ArgumentError)
We looked up into the stack trace and we found the problem was being caused by this line:
vendor/rails/activerecord/lib/active_record/base.rb:2195:in `compute_type’
When we checked the code, we found a dead-end with a class_eval invocation (oh meta-programming damn you on debugging times)
# Returns the class type of the record using the current module as a prefix. So descendants of
# MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.
def compute_type(type_name)
modularized_name = type_name_with_module(type_name)
silence_warnings do
begin
class_eval(modularized_name, __FILE__, __LINE__)
rescue NameError
class_eval(type_name, __FILE__, __LINE__)
end
end
end
This error was caused in the first place because we created a new environment for running the app, we checked the files on config/environments/ to see the differences between them; we didn’t find that many, commenting the few lines that were different didn’t make any change.
A (very long) while later, we noticed that the config/amazon_s3.yml file didn’t have a set of keys for the environment we were trying to run, after adding them everything went by pretty smoothly.
What pissed me off (and probably this guy as well) is that the error displayed didn’t make any sense at all, wtf is “Object is not missing constant Photo!”?, seriously? I investigated a bit further and it seems to be related with the autoload feature of the Rails framework, geez thanks for the cryptic error message ¬¬
I hope this info helps some unfortunate developer out there.
