Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.7 is incompatible with rails 3.0.x #197

Closed
alex2 opened this issue Feb 4, 2013 · 3 comments
Closed

Version 2.7 is incompatible with rails 3.0.x #197

alex2 opened this issue Feb 4, 2013 · 3 comments
Assignees
Milestone

Comments

@alex2
Copy link

alex2 commented Feb 4, 2013

Since upgrading to the latest version of paper_trail (from 2.6 to 2.7), our 3.0.20 rails project has been throwing an exception NoMethodError (undefined method dump' for Object:Class)whenever we try to save any model instances that declareserialize :foo` for some field.

After delving into the problem, it appears that paper_trail's new means of serializing serialize attributes on models in version 2.7 seems to be causing my rails 3.0.20 installations to flip out.

The changes here: v2.6.4...v2.7.0#L5R88 specifically the use of ModelName.serialized_attributes['column_name'].dump and ModelName.serialized_attributes['column_name'].load are causing issues with 3.0.20 where ActiveRecord::Coders sadly doesn't exist.

To demonstrate, given a Person model with serialize :name set.

# with rails 3.2.11
irb(main):002:0> Person.serialized_attributes
=> {"name"=>#<ActiveRecord::Coders::YAMLColumn:0x0000000323e788 @object_class=Object>}

Note that above with 3.2.11, the ActiveRecord::Coders::YAMLColumn has both .dump and .load methods available as required.

# with rails 3.0.20
1.8.7-p371 :003 > Person.serialized_attributes
 => {"name"=>Object}

Note that with 3.0.20 the default serialization class Object has no .dump method, and an unrelated .load method. This seems to be because in 3.0.20 the ModelName.serialized_objects hash values contain the class used to validate the output of the unserialized model attribute, however in 3.1.* the serialized_objects hash values instead contain the coder class, as specified by encode_with, defaulting to YAML.

I hope I'm on the right track but I'm surprised no one else has pointed out this incompatibility yet... I'll keep my fingers crossed that there isn't a massive message in your README saying that 2.7 is incompatible with rails 3.0.

@ghost ghost assigned batter Feb 4, 2013
@batter
Copy link
Collaborator

batter commented Feb 4, 2013

Thanks for the bug report. You are correct about this. Looks like pull #180 is the culprit here. The idea for the pull was absolutely spot on, in the sense that PaperTrail should store serialized versions of objects in the Version table, however, the author must not have realized (I did not either when I approved this pull) that Rails 3.0 does not return a Coder in the serialized_attributes hash.

This isn't a total incompatibility with Rails 3.0.x, but it does cause issues for users who are serializing model attributes.

@batter batter closed this as completed in 9f9032a Feb 4, 2013
@alex2
Copy link
Author

alex2 commented Feb 6, 2013

Impressive response time! I've just tested and the tip of master is working great with our 3.0.20 project (and will switch permanently when you release 2.7.1). Many thanks.

@batter
Copy link
Collaborator

batter commented Feb 6, 2013

Cheers, thanks for the heads up, otherwise I wouldn't have been aware of it. I'm actually a lot happier with this implementation since it essentially provides a fail-safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants