-
Notifications
You must be signed in to change notification settings - Fork 44
Transactions - Bug when using transaction APIs explicitly (not through the context manager) #447
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
Comments
I believe currently, transactions are designed to only work as part of a context manager That said, I think it would be a good idea to re-structure it so that it can be used without a context manager, as in your example |
The official documentation states:
I'd suggest either changing the behaviour (which should be a matter of moving the logic from |
Ok, good catch. I'll mark this as a bug again then. We should make sure to add tests for this use case as well |
After looking closer at the code, it's clear the intention is that only context managers are automatically associated with the If calling managing the lifecycle manually, you can still read data without conflict using I opened #578 to update the docstrings to hopefully make things more clear, and add the new test that avoids context managers |
TL;DR : when using
trx.begin()
andtrx.commit()
the transactions don't behave as expected.Please refer to this merge request to see the bug highlighted in the test.
From a quick look at the code, the problem seems to be the transaction is not added to the
client._batch_stack
when the APIs are called explicitly._push_batch
an_pop_batch
are called only through the context manager__enter__
and__exit__
.Because of this
client.current_batch
andcurrent_transaction
Environment details
3.8.16
22.0.4
google-cloud-datastore
version:2.15.2
Steps to reproduce
client.transaction()
txn.begin()
entity_in_txn = client.get(key)
txn.commit()
The transaction should raise a
Conflit
but it doesn't.(When doing the same with the context manager the Exeption is raised, see here
Code example
See here
Stack trace
The text was updated successfully, but these errors were encountered: