GeezerVison is showing github.com — DISCUSSION: Is there a way for a Transaction to indicate success/failure from __exit__ · Issue #496 · googleapis/google-cloud-python
DISCUSSION: Is there a way for a Transaction to indicate success/failure from __exit__ #496DescriptionFrom #336.
Currently, there is no way to determine if this occurs. It's unclear what a way forward would look like but in ndb transactions have retries and can create Future objects which know about the success or failure. Activitytseaver commented on Jan 7, 2015 The transaction package has a concept of a "doomed" transaction: one which is in a hosed state, from which it can never be committed. Having our code fail inside __exit__ would be something like that with two sharp edges:
- Failing while committing is actually more reasonable: the back-end might actually barf here.
- Failing while aborting is a real problem: which exception should surface?
FWIW, the Zope transaction's "two-phase commit" tries to deal with the problems of the first, by breaking up the "commit" into slices, for distribution across multiple resource managers (e.g., a database and a mail-sender). For each of the following methods, the transaction calls each resource manager in turn):
tpc_begin (can we commit?)
commit(do the work, but don't finalize)
tpc_vote (were there problems? last chance to back out)
tpc_finish (finalize; this must never fail: if it does, we've lost consistency)
tpc_abort (called if any RM raises from tpc_vote: must never fail).
dhermes commented on Jan 8, 2015 ContributorAuthor More actions For the most part the backend handles this.
It seems a concept of "doomed" would be nice since it would make it so that.
txn = Transaction()
with txn:
entity.save()
...
# This fails since txn has already been used, hence is doomed.
with txn:
new_entity.save()
I was thinking something simple along the lines of
>>> txn.in_progress
False
>>> txn.succeeded
True
>>> txn.finished
True
There seem to be less than 8 states (implied by 3 bools) but more than 4, so maybe there is a better way to get the information to answer the questions:
txn is in progress or not?
txn has already been "used"?
txn finished in commit (success) or rollback (failure)
elibixby commented on Jan 8, 2015 You also need some way to get auto allocated keys back from the transaction right? Could this be incorporated into the method which indicates failure or success? added 2 commits that reference this issue on Feb 5, 2015This issue will close once commit 63265b0 is merged into the 'master' branch.63265b0 This issue will close once commit 52f3fa8 is merged into the 'master' branch.52f3fa8 added 2 commits that reference this issue on Mar 9, 2026This issue will close once commit 6e461e6 is merged into the 'main' branch.6e461e6 This issue will close once commit 533bdf2 is merged into the 'main' branch.533bdf2
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|