aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-07 17:33:48 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-07 17:33:48 -0300
commit8d8d4f1560264cd1c74364d67fa0501f6dd2c4fa (patch)
treeb135372a1b4094343476205c57a9b6b756c41ca3 /activerecord/lib/active_record
parent37c1e47da09fba4ee76143da05bbd4faabbaa53e (diff)
parent998ba0e7084345a045d49a64ee9cf9d2d2441780 (diff)
downloadrails-8d8d4f1560264cd1c74364d67fa0501f6dd2c4fa.tar.gz
rails-8d8d4f1560264cd1c74364d67fa0501f6dd2c4fa.tar.bz2
rails-8d8d4f1560264cd1c74364d67fa0501f6dd2c4fa.zip
Merge pull request #13166 from bogdan/transaction-magic
[Regression 3.2 -> 4.0] Fix bugs with changed attributes tracking when transaction gets rollback
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/core.rb1
-rw-r--r--activerecord/lib/active_record/transactions.rb6
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 4571cc0786..22870fb6c5 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -505,7 +505,6 @@ module ActiveRecord
@destroyed_by_association = nil
@new_record = true
@txn = nil
- @_start_transaction_state = {}
@transaction_state = nil
@reflects_state = [false]
end
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 17f76b63b3..33c9af3d3d 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -341,6 +341,7 @@ module ActiveRecord
# Save the new record state and id of a record so it can be restored later if a transaction fails.
def remember_transaction_record_state #:nodoc:
+ @_start_transaction_state ||= {}
@_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key)
unless @_start_transaction_state.include?(:new_record)
@_start_transaction_state[:new_record] = @new_record
@@ -350,6 +351,8 @@ module ActiveRecord
end
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
@_start_transaction_state[:frozen?] = @attributes.frozen?
+ @_start_transaction_state[:changed_attributes] ||= changed_attributes
+ @_start_transaction_state
end
# Clear the new record state and id of a record.
@@ -368,6 +371,9 @@ module ActiveRecord
@attributes = @attributes.dup if @attributes.frozen?
@new_record = restore_state[:new_record]
@destroyed = restore_state[:destroyed]
+ changed_attributes.replace(restore_state[:changed_attributes]).delete_if do |attribute, old_value|
+ old_value == @attributes[attribute]
+ end
if restore_state.has_key?(:id)
write_attribute(self.class.primary_key, restore_state[:id])
else