-
-
Notifications
You must be signed in to change notification settings - Fork 901
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
models_committed signal triggered too early with nested transactions #645
models_committed signal triggered too early with nested transactions #645
Comments
I am confused by this description. It looks like the Edit: After checking in more detail, I found out that unlike the |
SQLAlchemy exposes after_transaction_end. |
That doesn't work, as that signal is emitted for every transaction end, not only the outer one. The solution adopted in #646 is to check explicitly if the transaction is nested or a subtransaction in all the different handlers. |
see close reason in associated PR #646 |
I would like to be able to determine when changes have been committed to the db so that a query from a different worker will see the new data.
It looks like I could use the
models_committed
signal, but it doesn't seem to work properly when using SAVEPOINT transactions. In that case, the signal gets sent on thecommit()
of the nested transaction, rather than the real commit of the full transaction to the database.This can be seen on the the following example:
The behavior I would expect is that the signal gets sent when doing the
commit()
on the last line, but instead the output is:due to the implicit
commit()
when exiting the context manager.One solution would be to modify https://github.com/mitsuhiko/flask-sqlalchemy/blob/50944e77522d4aa005fc3c833b5a2042280686d3/flask_sqlalchemy/__init__.py#L212 in order to detect whether the current transaction is nested, and don't do anything in that case.
Is there any other way to reliably detect when a transaction has been committed?
The text was updated successfully, but these errors were encountered: