fix(spanner): guard against empty exc.errors in run_in_transaction#17905
fix(spanner): guard against empty exc.errors in run_in_transaction#17905abhi-0203 wants to merge 1 commit into
Conversation
When run_in_transaction catches an Aborted exception with an empty
errors list (e.g. manually instantiated Aborted('...')), it crashes
with an uncaught IndexError on exc.errors[0]. Add a guard to fall
back to default_retry_delay when exc.errors is empty.
Closes googleapis#17903
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the run_in_transaction method in session.py to safely handle cases where an Aborted exception is raised with an empty errors list. By checking if exc.errors is populated before accessing its first element, it prevents potential IndexError exceptions. There are no review comments provided, so I have no additional feedback to offer.
Summary
Guard against empty
exc.errorsinSession.run_in_transactionto preventIndexError.Bug: When
run_in_transactioncatches anAbortedexception with an emptyerrorslist (e.g. manually instantiatedAborted("...")), it crashes withIndexError: list index out of rangeonexc.errors[0].Fix: Add a conditional guard:
exc.errors[0] if exc.errors else None. Whenexc.errorsis empty,Noneis passed to_get_retry_delay, which gracefully falls back todefault_retry_delayor exponential backoff (2**attempts + random()).Applied to both occurrences in
run_in_transaction(lines 545-547 and 582-584).Reproducer:
Closes #17903