aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-11 19:40:26 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-05-11 19:57:22 +0900
commitab3ad6a9ad119825636153cd521e25c280483340 (patch)
treeef7e87a1e06d771f24d7eb714a9623dc36b6431a /activerecord/lib/active_record/persistence.rb
parent5ed8aa9e02014d7840e746f407068315d6fc6b63 (diff)
downloadrails-ab3ad6a9ad119825636153cd521e25c280483340.tar.gz
rails-ab3ad6a9ad119825636153cd521e25c280483340.tar.bz2
rails-ab3ad6a9ad119825636153cd521e25c280483340.zip
`becomes` should clear the mutation tracker which is created in `after_initialize`
`becomes` creates new object and copies attributes from the receiver. If new object has mutation tracker which is created in `after_initialize`, it should be cleared since it is for discarded attributes. But if the receiver doesn't have mutation tracker yet, it will not be cleared properly. It should be cleared regardless of whether the receiver has mutation tracker or not. Fixes #32867.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index c2393c1fc8..a0d5f1ee9f 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -373,7 +373,7 @@ module ActiveRecord
became = klass.allocate
became.send(:initialize)
became.instance_variable_set("@attributes", @attributes)
- became.instance_variable_set("@mutations_from_database", @mutations_from_database) if defined?(@mutations_from_database)
+ became.instance_variable_set("@mutations_from_database", @mutations_from_database ||= nil)
became.instance_variable_set("@changed_attributes", attributes_changed_by_setter)
became.instance_variable_set("@new_record", new_record?)
became.instance_variable_set("@destroyed", destroyed?)