Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Base.execute_callstack_for_multiparameter_attributes doesn't appear to handle serialized columns

#3791

I'm getting "... error(s) on assignment of multiparameter attributes" out of execute_callstack_for_multiparameter_attribute on a serialized column that is a Time because column_for_attributes returns String.

This line inserted after the call to column_for_attributes (line #3055 Documentation for belongs_to incorrectly advertises Post#author? in base.rb for 2.3.5) is my take at fixing things up:

klass = (Time.is_a?(self.class.serialized_attributes[name]) ? Time :

    (Date.is_a?(self.class.serialized_attributes[name]) ? Date : self.class.serialized_attributes[name])) if self.class.serialized_attributes.key?(name)

My column is serialized generically as an Object which leads to the is_a? 's

Reported by Mike Summers · January 26th, 2010 @ 09:57 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Mike Summers
    Mike Summers
    • No changes were found…

    January 26th, 2010 @ 09:58 PM

  2. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • Importance changed from to Low

    Hi,

    Do you still see this bug on current 3.0.1? Could you provide a failing test case?

    Thanks

    October 17th, 2010 @ 05:36 PM

  3. Aditya Sanghi
    Aditya Sanghi

    Hi Mike,

    We're currently discussing refactoring of the multiparameter assignment in ticket 4346. You may want to have a look at that thread too but although that issue is related to multiparameter and time class, it is not dealing specifically with serialized attributes.

    Additionally, i think the solution you are suggesting is only for serialized attributes which although an edge use case, it not the usual way to do things.

    Currently the klass of the attribute is determined by reflection over an association OR by column_for_attribute(name_of_column). The class is finally determined by sending the method "klass" on the returned object. You need to update your model, to ensure that column_for_attribute(your_serialized_column) returns a Time Column object, so that running "klass" on it returns "Time", then you're set to go.

    The code below should get you started.

      class YourModel < ActiveRecord::Base
        columns_hash["your_serialized_time_column"] = ActiveRecord::ConnectionAdapters::Column.new("your_serialized_time_column", nil, "time")
      end
    

    Do let us know if this helps you.

    October 17th, 2010 @ 06:54 PM

  4. Aditya Sanghi
    Aditya Sanghi
    • State changed from new to wontfix

    Not sure if there is any clean way to determine the class of the serialized attribute. Closing this ticket as wontfix given that the above solution should work. Can re-open if the solution above doesnt work.

    October 21st, 2010 @ 11:32 AM