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

Commit 3ea264f

Browse files
committed
chore: make precommit token check emulator-proof
The Emulator returns an empty pre-commit token when a commit is attempted without a pre-commit token. This is different from not returning any pre-commit token at all. The check for 'did the Commit return a pre-commit token?' did not take this into account, which caused commits on the Emulator that needed to be retried, not to be retried. This again caused multiple test errors when running on the Emulator, as this would keep a transaction present on the test database on the Emulator, and the Emulator only supports one transaction at a time. These test failures went unnoticed, because the test configuration for the Emulator had pinned the Emulator version to 1.5.37, which did not support multiplexed sessions. This again caused the tests to fall back to using regular sessions. This change fixes the check for whether a pre-commit token was returned by a Commit. It also unpins the Emulator version for the system tests using default settings. This ensures that the tests actually use multiplexed sessions.
1 parent ffa5c9e commit 3ea264f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.github/workflows/integration-tests-against-emulator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
services:
1212
emulator:
13-
image: gcr.io/cloud-spanner-emulator/emulator:1.5.37
13+
image: gcr.io/cloud-spanner-emulator/emulator
1414
ports:
1515
- 9010:9010
1616
- 9020:9020

google/cloud/spanner_v1/transaction.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,20 @@ def before_next_retry(nth_retry, delay_in_seconds):
328328
# successfully commit, and must be retried with the new precommit token.
329329
# The mutations should not be included in the new request, and no further
330330
# retries or exception handling should be performed.
331-
if commit_response_pb.precommit_token:
331+
if commit_response_pb._pb.HasField("precommit_token"):
332332
add_span_event(span, commit_retry_event_name)
333+
nth_request = database._next_nth_request
333334
commit_response_pb = api.commit(
334335
request=CommitRequest(
335336
precommit_token=commit_response_pb.precommit_token,
336337
**common_commit_request_args,
337338
),
338-
metadata=metadata,
339+
metadata=database.metadata_with_request_id(
340+
nth_request,
341+
1,
342+
metadata,
343+
span,
344+
),
339345
)
340346

341347
add_span_event(span, "Commit Done")

tests/unit/test_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def _commit_helper(
533533
)
534534
commit.assert_any_call(
535535
request=expected_retry_request,
536-
metadata=base_metadata,
536+
metadata=expected_retry_metadata,
537537
)
538538

539539
if not HAS_OPENTELEMETRY_INSTALLED:

0 commit comments

Comments
 (0)