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

transaction 3.0 breaks afterCommitHooks #98

Closed
icemac opened this issue Nov 6, 2020 · 7 comments
Closed

transaction 3.0 breaks afterCommitHooks #98

icemac opened this issue Nov 6, 2020 · 7 comments
Assignees
Labels

Comments

@icemac
Copy link
Member

icemac commented Nov 6, 2020

What I did:

A customer has an application using ZODB and zope.sqlalchemy running on transaction 2.4.0. I wanted to upgrade it to 3.0.
In the afterCommitHook the relational database is accessed via zope.sqlalchemy, changes are made and committed.
This worked in 2.4 because in tpc_finish the database session is closed and self._free() is called before calling the after commit hooks. This way the after commit hook had a clean state to start a new transaction.

What actually happened:

transaction 3.0 moved the self._free() call after calling the after commit hooks, see c76fd72#diff-b36b9bfe40a935a0303d1998fd1e0b8c1a062ced96eb4f92858e3b73409352c7L315-R323.

Using zope.sqlalcemy in the after commit hook now requires it to join the transaction because in tpc_finish it closed its session and forgot the knowledge about the zope transaction. But joining a transaction in the status committed is prohibited.

zope.sqlalchemy always seems to try to join the zope transaction. If that fails, it already had created the internal SQLAlchemy transaction. So using try-except in this case creates problems later on when SQLAlchemy thinks it does not have to join the zope transaction because it already has is internal transaction object initialized.

Blindly starting a new transaction in the application code used in the after commit hook is no solution as it is also used by code running inside the transaction.

Questions

  • Was the change of calling self._free() earlier intended to change a broken (?) behavior?
  • Are there any suggestions how to act inside an after commit hook now, when having the need to commit something? (Was this ever supposed to be possible?)
  • Is my issue a problem in transaction, zope.sqlalchemy, or in the application code?

What version of Python and Zope/Addons I am using:

  • transaction 2.4 -> 3.0
  • Python 3.7
  • zope.sqlalchemy 1.3
  • SQLAlchemy 1.3.20

I am going to assign this to @d-maurer as the author of the change in transaction 3.0 but maybe others have an opinion, too.

@d-maurer
Copy link
Contributor

d-maurer commented Nov 6, 2020 via email

@d-maurer
Copy link
Contributor

d-maurer commented Nov 9, 2020 via email

@d-maurer
Copy link
Contributor

d-maurer commented Nov 9, 2020 via email

@icemac
Copy link
Member Author

icemac commented Nov 11, 2020

So it seems that the postCommitHooks should not do anything what has to be transactional or triggers the transaction machinery. Let's see what I can do with this knowledge in the application of the customer.

@icemac
Copy link
Member Author

icemac commented Nov 11, 2020

@d-maurer Thank you for looking into this and answering my questions.

Id like to keep this issue open for a while und I found a solution together with the customer.

@d-maurer
Copy link
Contributor

d-maurer commented Nov 11, 2020 via email

@icemac icemac added wontfix and removed question labels May 19, 2021
@icemac
Copy link
Member Author

icemac commented May 19, 2021

@d-maurer Thank you for your suggestion it helped for one problem but broke other tests with different strange error messages. So the recommendation would be to move the code outside the after commit hook and run it asynchronously.

As no-one else seems to have this problem, I am closing the issue.

@icemac icemac closed this as completed May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants