Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression on after_commit in nested transactions. #16432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
@@ -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
Expand Down
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/transaction_callbacks_test.rb
Expand Up @@ -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}
Expand Down