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 before_commit when updating a record on the callback #19325

Closed
wants to merge 1 commit into from

Conversation

arthurnn
Copy link
Member

This is fixing a bug, and refactoring the code a bit.

Bug:

before_commit was called after the transaction was poped from the stack, that caused any update on that callback to not join that transaction.

I fixed that bug in here, and cleaned up the code on commit_transaction , so now, the commit_records or add_to_transaction decision is on the transaction object, which is the one that holds the records anyways.
I think this implementation is cleaner, so instead of we check the joinable flag on the commit, we check when we create a new transaction.
I would like to know what @jeremy things about this tho.

(#19324 is falling because of we need this fix for the touch calls)

@@ -147,6 +151,8 @@ def initialize(connection)
end

def begin_transaction(options = {})
options[:run_callbacks] ||= !current_transaction.joinable?
Copy link
Member Author

Choose a reason for hiding this comment

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

this will allow anyone that creates a new transaction to force that transaction to run callbacks. I think this is a good feature to have. But I cannot think about use cases, so I am not sure if we should add it or not.. In any case, if we dont want that feature I can just remove the || from this line.

Copy link
Member

Choose a reason for hiding this comment

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

-1 to expose it. This mutates options argument as well.

Would consider passing a separate keyword argument instead, e.g.:

RealTransaction.new(@connection, options, run_commit_callbacks: !current_transaction.joinable?)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah.. i was not sure about this API.
I like your suggestion, will do that.. thanks!

@arthurnn
Copy link
Member Author

merged via 0d76ab9

@arthurnn arthurnn closed this Mar 14, 2015
@arthurnn arthurnn deleted the fix_before_commit_cb branch March 14, 2015 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants