From 9c4899d5f3f63d631fa02b8caf3be549e69994d5 Mon Sep 17 00:00:00 2001 From: abhi-0203 Date: Mon, 27 Jul 2026 04:38:28 +0000 Subject: [PATCH] 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 --- .../google/cloud/spanner_v1/session.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/google-cloud-spanner/google/cloud/spanner_v1/session.py b/packages/google-cloud-spanner/google/cloud/spanner_v1/session.py index 308c5d323624..32fe74b5cc14 100644 --- a/packages/google-cloud-spanner/google/cloud/spanner_v1/session.py +++ b/packages/google-cloud-spanner/google/cloud/spanner_v1/session.py @@ -543,7 +543,9 @@ def run_in_transaction(self, func, *args, **kw): except Aborted as exc: previous_transaction_id = txn._transaction_id delay_seconds = _get_retry_delay( - exc.errors[0], attempts, default_retry_delay=default_retry_delay + exc.errors[0] if exc.errors else None, + attempts, + default_retry_delay=default_retry_delay, ) attributes = dict(delay_seconds=delay_seconds, cause=str(exc)) attributes.update(span_attributes) @@ -580,7 +582,9 @@ def run_in_transaction(self, func, *args, **kw): except Aborted as exc: previous_transaction_id = txn._transaction_id delay_seconds = _get_retry_delay( - exc.errors[0], attempts, default_retry_delay=default_retry_delay + exc.errors[0] if exc.errors else None, + attempts, + default_retry_delay=default_retry_delay, ) attributes = dict(delay_seconds=delay_seconds) attributes.update(span_attributes)