| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
(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"). |
Sorry, something went wrong.
|
OK, good call on that.
|
Sorry, something went wrong.
|
Sorry, something went wrong.
|
Well without this, there is no indication if the context manager exited with commit() or rollback() and there is no way to tell. People could have something like with Transaction() as xact:
datastore.put([entity])
datastore.delete([key1, key2])
foo()and foo() could be raising, causing a rollback(), so it would be nice to check if xact.succeeded. Doing sequential / dependent transactions would also rely on knowing that the previous commit succeeded (lot's of transient failures possible, like short-term 503 and 429 errors.) |
Sorry, something went wrong.
|
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 commit() or rollback() directly: xact = Transaction()
xact.put([entity])
xact.delete([key1, key2])
try:
foo():
except SomeErrorType:
xact.rollback()
else:
xact.commit() |
Sorry, something went wrong.
|
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 __exit__ returns something Truth-y). Mind if I add a comment to the code explaining this? Thus succeeded is not necessary. I'll axe it, but leave the rest of the code in and ping you when updated. |
Sorry, something went wrong.
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 succeeded, and switched to using 4 enum values. PTAL. |
Sorry, something went wrong.
|
OK, one final question: do we want to expose a public, read-only status property (and therefore make the quasi-enum constants public too?). |
Sorry, something went wrong.
|
I don't see a reason to too at this time, and would rather not commit to it without a concrete use case. With the private implementation, this PR really just serves to keep begin() from begin called twice. |
Sorry, something went wrong.
|
OK, LGTM |
Sorry, something went wrong.
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>
* feat: adds ability to provide redirect uri * renames redirect_uri variable * adds js folder to sphinx and auth_redirect_uri * feat: adds javascript functionality related to oauth * feat: adds javascript functionality related to oauth * feat: adds sample authcodescript * feat: adds ability to host oauth page with the documentation * adds clarity to the user interface messaging * updates linting, toctree * updates minimum version of pydata-google-auth * Update docs/_static/js/authcodescripts.js * adds check to avoid override of user given clientid, clientsecret * adds parameters to the func to_gbq * adds docstrings related to three new parameters * Apply suggestions from code review * fix rst formatting * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Tim Swast <swast@google.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
E.g. protobuf/any.proto will be imported as from google.protobuf import any_pb2 as gp_any # Was previously 'as any'
Co-authored-by: ohmayr <omairnaveed@ymail.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Source-Link: googleapis/synthtool@571ee2c Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:09af371bb7d8ebbaef620bfc76c0a3a42da96d75f4821409b54f3466d4ebbd3c Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
Fixes #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 initially tried to do this stuff in Batch.__enter__ and Batch.__exit__ but the re-use policies differ and I wanted this to work outside of context managers. LMK what you think.