NoMethodError: undefined method `unserialized_value' #119

fuuka opened this Issue Aug 2, 2012 · 4 comments


None yet

3 participants

fuuka commented Aug 2, 2012

If using this gem, error occured when copying ActiveRecord object which contains serialized column.


source ''

gem 'rails', '3.2.6'
gem 'sqlite3'
gem 'composite_primary_keys'


class Temp < ActiveRecord::Base
  attr_accessible :item
  serialize :item, Array
$ rails c
Loading development environment (Rails 3.2.6)
1.9.3p194 :001 > r1 =
 => #<Temp id: nil, item: [], created_at: nil, updated_at: nil> 
1.9.3p194 :002 > r2 = r1.dup
(Object doesn't support #inspect)
1.9.3p194 :003 > r2.item
NoMethodError: undefined method `unserialized_value' for []:Array
    from /Users/**/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/attribute_methods/read.rb:72:in `__temp__'
    from (irb):3
    from /Users/**/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /Users/**/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /Users/**/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
cfis commented Aug 8, 2012

Thanks for the report. Will take a look - or if you want to make a patch happy to accept it.

tism commented Sep 24, 2012

The problem seems to stem from composite_primary_keys/base.rb vs active_record/base.rb (I haven't checked against master yet). The missing line of code causes the attributes to be initialised with unserialization, however without it the attributes are accessed normally and unserialized on demand. The method that is eventually triggering the issue is the method generated for the attribute which is generated in attribute_methods/read.rb. I'm running a quick hack against my project's test suite to see what happens, if that turns out a patch should be trivial.

cfis commented Sep 30, 2012

Can you see if 5.0.9 fixes the issue?

fuuka commented Oct 1, 2012

Hi, I tried 5.0.9 and it seems to be working fine. Thanks for the fix.

@fuuka fuuka closed this Oct 1, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment