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

Conversation

arthurnn
Copy link
Member

@arthurnn arthurnn commented Aug 8, 2014

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]

review @rafaelfranca @chancancode
this should be applied on 4-0-stable too.
I will work on a different fix for master, as the code is different.

@arthurnn
Copy link
Member Author

arthurnn commented Aug 8, 2014

cc @jeremy

@@ -201,6 +201,7 @@ def perform_commit
@state.set_state(:committed)
@state.parent = parent.state
connection.release_savepoint
records.delete_if { |r| parent.add_record(r) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too clever for my taste :)

Why do we need to delete the records from this array anyway? rollback_records doesn't seem to do that.

But if we have to for some reason, I'd rather do a records.each followed by a records.clear

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need to delete them. You are right too fancy =), will just replace this with a normal .each

@chancancode chancancode added this to the 4.1.5 milestone Aug 11, 2014
@chancancode chancancode self-assigned this Aug 11, 2014
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 rails#16425]
chancancode added a commit that referenced this pull request Aug 12, 2014
…_trans

Fix regression on after_commit in nested transactions.
@chancancode chancancode merged commit b31c49c into rails:4-1-stable Aug 12, 2014
chancancode added a commit that referenced this pull request Aug 12, 2014
…_trans

Fix regression on after_commit in nested transactions.
@arthurnn arthurnn deleted the after_commit_run_on_top_level_trans branch August 12, 2014 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants