Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit a840b3b

Browse files
committed
fix(spanner): resolve transport mismatches and DBAPI transaction retry errors
1 parent 3448a12 commit a840b3b

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

google/cloud/spanner_dbapi/cursor.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,21 @@ def _execute(self, sql, args=None, call_from_execute_many=False):
327327
self._execute_in_rw_transaction()
328328

329329
except (AlreadyExists, FailedPrecondition, OutOfRange) as e:
330-
exception = e
331-
raise IntegrityError(getattr(e, "details", e)) from e
330+
exception = IntegrityError(getattr(e, "details", e))
331+
exception.__cause__ = e
332+
raise exception
332333
except InvalidArgument as e:
333-
exception = e
334-
raise ProgrammingError(getattr(e, "details", e)) from e
334+
exception = ProgrammingError(getattr(e, "details", e))
335+
exception.__cause__ = e
336+
raise exception
335337
except InternalServerError as e:
336-
exception = e
337-
raise OperationalError(getattr(e, "details", e)) from e
338+
exception = OperationalError(getattr(e, "details", e))
339+
exception.__cause__ = e
340+
raise exception
338341
except Exception as e:
339342
exception = e
340343
raise
344+
341345
finally:
342346
if not self._in_retry_mode and not call_from_execute_many:
343347
self.transaction_helper.add_execute_statement_for_retry(

google/cloud/spanner_v1/_async/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@
6262
from google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.grpc import (
6363
InstanceAdminGrpcTransport,
6464
)
65+
6566
from google.cloud.spanner_admin_instance_v1 import (
6667
ListInstanceConfigsRequest,
6768
ListInstancesRequest,
6869
)
70+
71+
6972
from google.cloud.spanner_v1._async.instance import Instance
7073
from google.cloud.spanner_v1._helpers import (
7174
_create_experimental_host_transport,
@@ -399,6 +402,7 @@ def instance_admin_api(self):
399402
client_options=self._client_options,
400403
transport=transport,
401404
)
405+
402406
elif self._experimental_host:
403407
from google.cloud.spanner_v1._async._helpers import (
404408
_create_experimental_host_transport as _create_experimental_host_transport_async,
@@ -416,6 +420,7 @@ def instance_admin_api(self):
416420
self._client_certificate,
417421
self._client_key,
418422
)
423+
419424
else:
420425
transport = _create_experimental_host_transport_sync(
421426
InstanceAdminGrpcTransport,
@@ -425,6 +430,7 @@ def instance_admin_api(self):
425430
self._client_certificate,
426431
self._client_key,
427432
)
433+
428434
self._instance_admin_api = InstanceAdminClient(
429435
client_info=self._client_info,
430436
client_options=self._client_options,
@@ -436,6 +442,7 @@ def instance_admin_api(self):
436442
client_info=self._client_info,
437443
client_options=self._client_options,
438444
)
445+
439446
return self._instance_admin_api
440447

441448
@property
@@ -453,6 +460,7 @@ def database_admin_api(self):
453460
client_options=self._client_options,
454461
transport=transport,
455462
)
463+
456464
elif self._experimental_host:
457465
from google.cloud.spanner_v1._async._helpers import (
458466
_create_experimental_host_transport as _create_experimental_host_transport_async,
@@ -470,6 +478,7 @@ def database_admin_api(self):
470478
self._client_certificate,
471479
self._client_key,
472480
)
481+
473482
else:
474483
transport = _create_experimental_host_transport_sync(
475484
DatabaseAdminGrpcTransport,
@@ -479,11 +488,13 @@ def database_admin_api(self):
479488
self._client_certificate,
480489
self._client_key,
481490
)
491+
482492
self._database_admin_api = DatabaseAdminClient(
483493
client_info=self._client_info,
484494
client_options=self._client_options,
485495
transport=transport,
486496
)
497+
487498
else:
488499
self._database_admin_api = DatabaseAdminClient(
489500
credentials=self.credentials,

google/cloud/spanner_v1/_async/database.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@
8383
SpannerGrpcTransport,
8484
)
8585

86+
8687
from google.cloud.spanner_v1._opentelemetry_tracing import (
8788
add_span_event,
8889
get_current_span,
8990
trace_call,
9091
)
92+
9193
from google.cloud.spanner_v1.metrics.metrics_capture import MetricsCapture
9294
from google.cloud.spanner_v1.table import Table
9395

@@ -487,6 +489,8 @@ def spanner_api(self):
487489
self._spanner_api = SpannerClient(
488490
client_info=client_info, transport=transport
489491
)
492+
493+
490494
return self._spanner_api
491495
if self._experimental_host is not None:
492496
from google.cloud.spanner_v1._async._helpers import (

0 commit comments

Comments
 (0)