-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Tracking status of Transaction as well as success / failure. #595
Conversation
(Originally mis-posted on #573): I'm not sure about the use case: won't the user have already handled an exception in the case that the transaction commit failed, or else have aborted it directly? On the implementation: handling two state fields seems awkward: there are nonsensical combinations of them (_status is None, but _commit_success is True, etc.). ISTM it would be better just to have self._status always be an integer, with values ranging from 0 ("initial"), 1 ("in progress"), 2 ("aborted"), 3 ("committed"). |
OK, good call on that.
|
|
Well without this, there is no indication if the context manager exited with with Transaction() as xact:
datastore.put([entity])
datastore.delete([key1, key2])
foo() and Doing sequential / dependent transactions would also rely on knowing that the previous commit succeeded (lot's of transient failures possible, like short-term |
Application code would've needed to catch an exception, and would therefore know that the transaction aborted, no? try:
with Transaction() as xact:
datastore.put([entity])
datastore.delete([key1, key2])
foo()
except SomeErrorType:
recover_from_error() Or else it would've been managing the transaction imperatively, and would have called xact = Transaction()
xact.put([entity])
xact.delete([key1, key2])
try:
foo():
except SomeErrorType:
xact.rollback()
else:
xact.commit() |
I was targeting the context manager case, not direct interaction, due to the case you illustrate above. I was also confused about context managers, thinking that they swallowed exceptions in all cases (only if Thus |
Fixes googleapis#496. NOTE: Some of these changes may belong on Batch, but the concept of "tombstone"-ing is unique to a Transaction (i.e. once started, can only be committed once and the transaction ID can never be used again).
@tseaver I rebased, removed |
def __init__(self, dataset_id=None, connection=None): | ||
super(Transaction, self).__init__(dataset_id, connection) | ||
self._id = None | ||
self._status = self._INITIAL | ||
self._commit_success = False |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
OK, one final question: do we want to expose a public, read-only |
I don't see a reason to With the private implementation, this PR really just serves to keep |
OK, LGTM |
Tracking status of Transaction as well as success / failure.
* chore: code formatting * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Fixes #496.
NOTE: Some of these changes may belong on
Batch
, but the conceptof "tombstone"-ing is unique to a Transaction (i.e. once started,
can only be committed once and the transaction ID can never be
used again).
@tseaver I initially tried to do this stuff in
Batch.__enter__
andBatch.__exit__
but the re-use policies differ and I wanted this to work outside of context managers. LMK what you think.