collectiveidea / audited

Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
MIT License
3.35k stars 645 forks source link

Audited Gem Breaks Marshal #106

Open TALlama opened 12 years ago

TALlama commented 12 years ago

Round-tripping of a collection of ActiveRecord objects fails when the ActiveRecord class being marshaled is audited. When marshaling two objects, the first object round-trips fine but the second is replaced by the symbol :@audit_comment (and the third is nil, if there is a third object).

    sam = User.create(name: "Sam")
    max = User.create(name: "Max")

    dumped = Marshal.dump([sam, max])
    loaded = Marshal.load(dumped)

    rt_sam = loaded.first
    assert_equal User, rt_sam.class, "We put two User objects in; we get one out"
    assert_equal 'Sam', rt_sam.name, "And he keeps his name"

    rt_max = loaded.last
    assert_equal User, rt_max.class, "But the second thing we get back isn't a User at all; it's #{rt_max.inspect}"
    assert_equal 'Max', rt_max.name, "And it wouldn't have a name if we asked it"

See full Rails app here: http://cl.ly/HTuL

I don't see where in the audited gem this might be happening; there's no _dump or marshal_dump overrides and no monkey-patching of Marshal. But it certainly is happening.

TALlama commented 12 years ago

I forgot to add that this bug causes slightly different effects when what you've marshaled is an ActiveRecord object with a has_many association to a group of audited ActiveRecord objects: the group fails to load just the same, but Rails provides you with the incredibly unhelpful error message dump format error for symbol(0x30), which only makes sense after you know that the thing that ActiveRecord::Association got back is a symbol (:@audit_comment) and not the ActiveRecord::Base object it was expecting.

julesce commented 11 years ago

I'm running into this 'dump format error for symbol' error as well.

Does anyone have a solution/work-around?

TALlama commented 11 years ago

My workaround was to stop using the audited gem and come back to it later. Wish I had better news than that. :-1:

julesce commented 11 years ago

So the same workaround as me then ;-)