Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11572 (new defect)

Opened 1 month ago

Column called "frozen" causes exception

Reported by: candlerb Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 2.0.1
Severity: normal Keywords:
Cc:

Description

I have a database table with a text column whose name happens to be "frozen"

This worked fine with AR 1.15.3, but causes an abort with AR 2.0.2:

/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:88:in `instance_method_already_implemented?': frozen? is defined by ActiveRecord (ActiveRecord::DangerousAttributeError)
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:76:in `define_attribute_methods'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:63:in `define_attribute_methods'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:187:in `method_missing'

I believe the problem starts around here, with an attempt to define both 'frozen' and 'frozen?' methods in the Base subclass for this table:

          unless instance_method_already_implemented?("#{name}?")
            define_question_method(name)
          end

Ruby already has a 'frozen?' public instance method in all objects.

I would like to avoid having to rename the database column with all the knock-on effects in controllers, views etc.

Since I'm not using this column as a boolean, I don't mind either of the following solutions:

1. Leave the existing Ruby 'frozen?' method alone 2. Override the Ruby 'frozen?' method

I don't mind having to use an explicit incantation to permit this behaviour.

BTW, here are all Object public methods which end with a question mark:

["eql?", "equal?", "frozen?", "instance_of?", "is_a?", "kind_of?", "nil?", "respond_to?", "tainted?"]

So I guess anyone using columns of those names (minus the question mark) would be affected.