This project is archived and is in readonly mode.
ActiveRecord marshal dump/load has a different behavior on boolean [rails]
-
prasanna
- Assigned user set to Aaron Patterson
I was wondering if this should be a bug report of a ticket?
-
Aaron Patterson
- State changed from new to needs-more-info
- Importance changed from to Low
I can't seem to reproduce this problem. What database are you using? What version of Rails? Can you share your schema?
Even better would be if you could supply a small rails app that reproduces the problem. I would really appreciate that! :-D
I've tried adding the following test to the AR test cases, but cannot reproduce the problem:
class Booleantest < ActiveRecord::Base; end def test_saving_after_marshal bool = Booleantest.new(:value => false) bool = Marshal.load Marshal.dump bool bool.value = nil bool.save bool.reload assert_nil bool.value end -
prasanna
DataBase: mysql
Rails: 2.3.5To reproduce it: You have to put the following statement in your after_save handler.
class Bool after_save :dumper def dumper $global = Marshal.load Marshal.dump self end end Bool.new(:value => false).save puts $global.value # is false -> OK $global.value = nil $global.save puts $global.value # is nil -> OK $global.reload puts $global.value # is false -> BADI owe you an apology for not testing Marshal.load Marshal.dump sequence. I was binary-searching the problem and this is what I got it down to. If you need any more info, or if you are unable to reproduce this, feel free to ping me. myprasanna@gmail.com
-
prasanna
It is probably not a deal-breaker. I am guessing, rails works like this:
@after_save_running = true # call the after_save handlers @after_save_running = falseAnd since I dump in the after_save handler, that variable gets dumped as true. The next time I try to save it fails, to do it, thinking the after_save handler is calling a save function, causing recursion. I think you can safely close this.
Thanks for your time.
-
Aaron Patterson
- State changed from needs-more-info to invalid