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
after_commit does not work as expected in nested transactions #536
Comments
@averell23 I'm also facing this issue in my application. I'm curious if you managed to work around this issue, and how. I have an aasm I have occasionally encountered situation where the job is picked up by Sidekiq worker, before the object is persisted to the database, and the job fails with error saying |
You can mitigate by not having calling the state change within another transaction, the hook works at expected if you call it outside a db transaction. You could also work with the |
A workaround
I'd like someone could help to fix this issue :) |
Any idea when a new version with the fix will be released? |
@mquan Thank you for the reminder Just released AASM |
@anilmaurya It's not working for me even after upgrading to the latest version. In my case, I'm doing multiple saves inside a single transaction. And, the after_commit hook is getting triggered before COMMIT |
@anilmaurya did you added As per Readme,
|
@stokarenko my bad, missed this. It's working after adding the dependency. Thanks for the help |
We are using aasm with activerecord and mysql/postgres for persistence. Today I found that the
after_commit
hook does not do what it says on the label, when you are in a nested transaction.What happens
The hook is called after the aasm_transaction is complete, but before the outermost transaction is completed. This means that it will be called after a
RELEASE SAVEPOINT
but before the database transaction isCOMMIT
ed to the database.What I expected
I had expected that the hook is only called after the database transaction
COMMIT
is done, that is, after the outermost database transaction is complete. This is also how the ActiveRecordafter_commit
hook works.Was this means
Currently in an
after_commit
callbackSee the code
aasm/lib/aasm/persistence/orm.rb
Line 134 in 2621948
The text was updated successfully, but these errors were encountered: