This project is archived and is in readonly mode.

#4751 ✓resolved
Andrew Bloomgarden

ActiveRecord::Base.compute_type swallows NoMethodError

Reported by Andrew Bloomgarden | June 2nd, 2010 @ 06:56 AM | in 3.0.2

If you have a model that has an invalid method at the class level, like so:

class InvalidModel < ActiveRecord::Base
  not_a_real_method
end

and another model that uses it as an association:

class OtherModel < ActiveRecord::Base
  has_many :invalid_models
end

when InvalidModel is autoloaded via something like other_model_instance.invalid_models, it should raise a NoMethodError.

However, the current implementation of compute_type, which Reflection calls, swallows every NameError assuming that means a constantize failure. NoMethodError is a subclass of NameError, though, so you just get an "uninitialized constant OtherModel::InvalidModel" error. Very misleading, and it didn't work like that in Rails 2.x.

I have a patch & test forthcoming.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages