You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm posting a new issue, as the old one is closed. Should I just use the old issue? Is someone tracking closed issues' comments?
I've spent some time debugging to get to the bottom of this. I didn't know you can't call save or update_attributes! inside of an after_commit ..., on: :create callback.
I think this is a bug and it should be considered for fixing. I can see in the other thread that some rails maintainers also confirmed this is a bug.
There's this PR from 3 years ago that apparently fixes this, but the PR was never merged: #18367
save inside a after_commit with on: :create is also inside the create lifecycle even if what it is doing is an update. The lifecycle only finish when the last after_commit callback runs, so we don't have a way to detect if that save is an update or not.
Not sure if we could have callback stack, like there is a function call stack. I'm just shooting an idea here.
How did it work before? This (revert) commit seems to revert the changes that introduced this bug. It seems like it's broken again.
System configuration
Rails version:
5.1.5 Ruby version:
2.4.2
The text was updated successfully, but these errors were encountered:
How did it work before? This (revert) commit seems to revert the changes that introduced this bug. It seems like it's broken again.
You have this backwards: #6226fixed the bug, and the commit you linked to reverted the fix because it had other undesirable effects. As far as I can tell, this bug has always been present since after_commit callbacks were added to Rails.
…commit`
Since a record is already persisted in `after_create_commit`, so `save`
should invoke only `after_update_commit`.
This bug is caused by depending on `@_start_transaction_state` for
rollback to consider whether it was `new_record` before being committed.
If after commit callbacks caused another commit, the state before
last commit is no longer `new_record`.
Fixes#32831.
Closes#18367.
Closes#31106.
This is the same issue like this one: after_commit :my_callback, :on => :create fires on update too
I'm posting a new issue, as the old one is closed. Should I just use the old issue? Is someone tracking closed issues' comments?
I've spent some time debugging to get to the bottom of this. I didn't know you can't call
save
orupdate_attributes!
inside of anafter_commit ..., on: :create
callback.I think this is a bug and it should be considered for fixing. I can see in the other thread that some rails maintainers also confirmed this is a bug.
There's this PR from 3 years ago that apparently fixes this, but the PR was never merged: #18367
@rafaelfranca said:
Not sure if we could have callback stack, like there is a function call stack. I'm just shooting an idea here.
How did it work before? This (revert) commit seems to revert the changes that introduced this bug. It seems like it's broken again.
System configuration
Rails version:
5.1.5
Ruby version:
2.4.2
The text was updated successfully, but these errors were encountered: