1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix regression on after_commit in nested transactions.

after_commit should not run in nested transactions, however they should
run once the outermost transaction gets committed. This patch fixes the
problem copying the records from the Savepoint to its parent. So the
RealTransaction will have all records that needs to run callbacks on it.

[fixes #16425]
This commit is contained in:
Arthur Neves 2014-08-08 15:46:00 -04:00
parent 0002954512
commit 2e90fe736d
No known key found for this signature in database
GPG key ID: 04A390FB1E433E17
3 changed files with 21 additions and 0 deletions

View file

@ -1,3 +1,9 @@
* Fix regression on after_commit that didnt fire when having nested transactions.
Fixes #16425
*arthurnn*
* Do not try to write timestamps when a table has no timestamps columns.
Fixes #8813.

View file

@ -111,6 +111,8 @@ module ActiveRecord
def commit
super
connection.release_savepoint(savepoint_name)
parent = connection.transaction_manager.current_transaction
records.each { |r| parent.add_record(r) }
end
def full_rollback?; false; end

View file

@ -129,6 +129,19 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
assert_equal [:commit_on_update], @first.history
end
def test_only_call_after_commit_on_top_level_transactions
@first.after_commit_block{|r| r.history << :after_commit}
assert @first.history.empty?
@first.transaction do
@first.transaction(requires_new: true) do
@first.touch
end
assert @first.history.empty?
end
assert_equal [:after_commit], @first.history
end
def test_call_after_rollback_after_transaction_rollsback
@first.after_commit_block{|r| r.history << :after_commit}
@first.after_rollback_block{|r| r.history << :after_rollback}