Skip to content

Commit 9c4899d

Browse files
committed
fix(spanner): guard against empty exc.errors in run_in_transaction
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 #17903
1 parent 4f21b8b commit 9c4899d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • packages/google-cloud-spanner/google/cloud/spanner_v1

packages/google-cloud-spanner/google/cloud/spanner_v1/session.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ def run_in_transaction(self, func, *args, **kw):
543543
except Aborted as exc:
544544
previous_transaction_id = txn._transaction_id
545545
delay_seconds = _get_retry_delay(
546-
exc.errors[0], attempts, default_retry_delay=default_retry_delay
546+
exc.errors[0] if exc.errors else None,
547+
attempts,
548+
default_retry_delay=default_retry_delay,
547549
)
548550
attributes = dict(delay_seconds=delay_seconds, cause=str(exc))
549551
attributes.update(span_attributes)
@@ -580,7 +582,9 @@ def run_in_transaction(self, func, *args, **kw):
580582
except Aborted as exc:
581583
previous_transaction_id = txn._transaction_id
582584
delay_seconds = _get_retry_delay(
583-
exc.errors[0], attempts, default_retry_delay=default_retry_delay
585+
exc.errors[0] if exc.errors else None,
586+
attempts,
587+
default_retry_delay=default_retry_delay,
584588
)
585589
attributes = dict(delay_seconds=delay_seconds)
586590
attributes.update(span_attributes)

0 commit comments

Comments
 (0)