Permalink
Browse files

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]
  • Loading branch information...
arthurnn committed Aug 8, 2014
1 parent c8d54cd commit d0993d9e50f9964897cf824bd1307747f30ae179
@@ -1,3 +1,9 @@
+* Fix regression on after_commit that didnt fire when having nested transactions.
+
+ Fixes #16425
+
+ *arthurnn*
+
* Define `id_was` to get the previous value of the primary key.
Currently when we call id_was and we have a custom primary key name
@@ -201,6 +201,7 @@ def perform_commit
@state.set_state(:committed)
@state.parent = parent.state
connection.release_savepoint
+ records.each { |r| parent.add_record(r) }
end
end
end
@@ -129,6 +129,19 @@ def test_only_call_after_commit_on_update_after_transaction_commits_for_existing
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}

0 comments on commit d0993d9

Please sign in to comment.