Dirty tracking on serialized columns is broken
Reported by Andre Foeken | June 7th, 2008 @ 01:48 AM | in 2.1.1
class Monkey < ActiveRecord::Base
serialize legs, Array
end
Now in the console:
>> m = Monkey.create
>> m.changed? => false
>> m.legs = [1,2,3]
>> m.changed? => false
Comments and changes to this ticket
-
Jeremy Kemper June 11th, 2008 @ 07:59 PM
- → Milestone changed from to 2.1.1
- → State changed from new to open
- → Assigned user changed from to Jeremy Kemper
-
Ernie Miller July 3rd, 2008 @ 02:51 PM
- → Tag changed from to activerecord bug dirty
Is this bug valid? I can't reproduce in Rails 2.1, anyway.
class Monkey < ActiveRecord::Base
serialize :legs, Array
end
And in script/console:
Loading development environment (Rails 2.1.0)
>> m = Monkey.create
=> #
>> m.changed?
=> false
>> m.legs = [1,2,3,4]
=> [1, 2, 3, 4]
>> m.changed?
=> true
-
Ernie Miller July 3rd, 2008 @ 02:58 PM
Hm. Trying once more since Lighthouse formatting eluded me.
class Monkey < ActiveRecord::Baseserialize :legs, Array
end
and
Loading development environment (Rails 2.1.0)>> m = Monkey.create
=> #
>> m.changed?
=> false
>> m.legs = [1,2,3,4]
=> [1, 2, 3, 4]
>> m.changed?
=> true
-
Ernie Miller July 3rd, 2008 @ 02:59 PM
Eh, I give up. Trying Textile but it's not working. You get the idea.
-
Ripta Pasay July 12th, 2008 @ 09:19 PM
I couldn't reproduce this either. I did, however, find that dirty tracking doesn't work with in-place manipulation of said serialized column:
>> m.legs => [1, 2, 3] >> m.changed? => false >> m.legs << 4 => [1, 2, 3, 4] >> m.changed? => falseIMHO, AR should let the object itself figure out whether it's been changed or not. If anything, AR could provide a way for either: (a) the serialized object to notify AR that the attribute has been changed, or (b) AR to optionally query the serialized object when its own #changed? is called.
-

quake wang July 13th, 2008 @ 04:04 AM
I can't reproduce this error in rails 2.1, however, dirty checking is broken is this case:
>> m.reload
>> m.legs = m.legs << 4
>> m.changed?
=> false
-
Jeremy Kemper July 16th, 2008 @ 12:20 AM
- → State changed from open to invalid
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
The Git repository resides at http://github.com/rails
Check out the current development trunk (Edge Rails) with:
git clone git://github.com/rails/rails.git
Creating or reviewing a patch
See the contributor guide.
Creating a feature request
Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".
