This project is archived and is in readonly mode.
ActiveRecord serialization throws SerializationTypeMismatch if I try to serialize a AR object
-
Neeraj Singh
- Importance changed from to Low
I am not able to reproduce this problem in Rails edge.
class Brake < ActiveRecord::Base serialize :car, Car end ree-1.8.7-2010.02 > Car.create! :name => 'honda' (0.2ms) SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' AREL (0.3ms) INSERT INTO "cars" ("name") VALUES ('honda') => #<Car id: 1, name: "honda"> ree-1.8.7-2010.02 > Brake.create! :car => Car.last Car Load (0.3ms) SELECT "cars".* FROM "cars" ORDER BY cars.id DESC LIMIT 1 AREL (0.5ms) INSERT INTO "brakes" ("car") VALUES ('--- !ruby/object:Car attributes: name: honda id: 1 attributes_cache: {} changed_attributes: {} destroyed: false marked_for_destruction: false new_record: false previously_changed: {} readonly: false ') => #<Brake id: 1, car: #<Car id: 1, name: "honda">> ree-1.8.7-2010.02 > Brake.last Brake Load (0.4ms) SELECT "brakes".* FROM "brakes" ORDER BY brakes.id DESC LIMIT 1 => #<Brake id: 1, car: #<Car id: 1, name: "honda">> ree-1.8.7-2010.02 > -
rmehner
Thank you Neeraj,
it's indeed fixed in Edge Rails. Unfortunately not in the stable releases.
Thank you for pointing me to the right direction and for your effort.
Greetings,
- Robin -
Neeraj Singh
- State changed from new to resolved
-
Bob Lail
- Tag set to workaround yaml serialize 3.0.3 issue
A workaround for Rails 3.0.3:
I spent a while scanning through commit between July 28 and December 4 and could not find a patch that atomically fixed this.
If you need to stay on the stable brach for the time being, this can serve as a workaround. Change this:
def []=(key, value) @keys << key unless has_key?(key) super endto this:
def []=(key, value) (@keys||=[]) << key unless has_key?(key) super endin
active_support/ordered_hash.rb. I know it's kind of ugly, but it's the smallest change that resolves the issue. -
Bob Lail
BTW, a short test for the problem is:
YAML.load "--- \n- &id001 !ruby/object:MonthlyOccurrence \n errors: !ruby/object:ActiveModel::Errors\n base: *id001\n hash: {}\n\n kind: day\n ordinal: 1"This works on Rails 2.3.9 and fails on Rails 3.0.3. (You don't need to have a
MonthlyOccurrenceclass defined in your project for YAML.load to work.) The stack trace shows there to be an issue deserializing OrderedHash, which is superclass of ActiveModel::Errors.