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

Execute the before_committed! callbacks on the most recent copy of the record #46525

Merged
merged 3 commits into from Nov 22, 2022

Conversation

rafaelfranca
Copy link
Member

Same as #36190 but for before_committed! callbacks.

Before only the early copy of the same record (different object ids, but
pointing to the same record in the database) was used to execute the
callback, but it didn't have the touch_later information.

Fixes #26726.

rafaelfranca and others added 3 commits November 21, 2022 22:33
The value of `touch_method` will always be `:touch_later`, so we can
remove all the complexity of passing it around.
…the record

Same as #36190 but for `before_committed!` callbacks.

Before only the early copy of the same record (different object ids, but
pointing to the same record in the database) was used to execute the
callback, but it didn't have the touch_later information.

Fixes #26726.

Co-authored-by: Wolfram Nikolas Müller <muellerwolfram@gmail.com>
@rafaelfranca rafaelfranca merged commit 28b5771 into main Nov 22, 2022
@rafaelfranca rafaelfranca deleted the rm-fix-touch branch November 22, 2022 23:00
eileencodes added a commit to eileencodes/rails that referenced this pull request Dec 8, 2022
This reverts commit 28b5771, reversing
changes made to dbd9311.
adrianna-chang-shopify added a commit to Shopify/rails that referenced this pull request Dec 15, 2022
This reverts commit 28b5771, reversing
changes made to dbd9311.
adrianna-chang-shopify added a commit to adrianna-chang-shopify/rails that referenced this pull request Dec 15, 2022
As of rails#46525, the behaviour around
before_committed! callbacks has changed: callbacks are run on every
enrolled record in a transaction, even multiple copies of the same record.
This is a significant change that apps should be able to opt into in order
to avoid unexpected issues.
@eraffel-MDSol
Copy link

eraffel-MDSol commented Feb 14, 2024

By switching from touch to always calling touch_later, the result is that _touch_row is no longer called on the touch, and as a result, the lock_version column is no longer incremented. I'm specifically seeing this when the record with the belongs_to is newly created. Is this a bug? If not, can you provide some guidance on a good workaround to restore that behavior?

@rafaelfranca
Copy link
Member Author

That is a bug. Can you open an issue with a way to reproduce? It is very likely this commit can be reverted since it isn't strictly necessary. It was jus a refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants