From 7d8f0c556b43265a8cf7715509892ac136d3da4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Mon, 13 Jan 2025 14:23:45 +0100 Subject: [PATCH] fix(spanner): ReadWriteStmtBasedTransaction would not remember options for retries (#11443) Any TransactionOptions that had been set for a ReadWriteStmtBasedTransaction would not be remember and carried over if the transaction was retried. This would cause the retry to for example miss the transaction tag. --- spanner/transaction.go | 1 + spanner/transaction_test.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spanner/transaction.go b/spanner/transaction.go index 94fb770ead53..be6ee4af7228 100644 --- a/spanner/transaction.go +++ b/spanner/transaction.go @@ -1886,6 +1886,7 @@ func newReadWriteStmtBasedTransactionWithSessionHandle(ctx context.Context, c *C return err } + t.options = options t.txOpts = c.txo.merge(options) t.ct = c.ct t.otConfig = c.otConfig diff --git a/spanner/transaction_test.go b/spanner/transaction_test.go index c17d40879cbe..5617951a9696 100644 --- a/spanner/transaction_test.go +++ b/spanner/transaction_test.go @@ -888,11 +888,14 @@ func testReadWriteStmtBasedTransaction(t *testing.T, executionTimes map[string]S if attempts > 1 { tx, err = tx.ResetForRetry(ctx) } else { - tx, err = NewReadWriteStmtBasedTransaction(ctx, client) + tx, err = NewReadWriteStmtBasedTransactionWithOptions(ctx, client, TransactionOptions{TransactionTag: "test"}) } if err != nil { return 0, attempts, fmt.Errorf("failed to begin a transaction: %v", err) } + if g, w := tx.options.TransactionTag, "test"; g != w { + t.Errorf("transaction tag mismatch\n Got: %v\nWant: %v", g, w) + } rowCount, err = f(tx) if err != nil && status.Code(err) != codes.Aborted { tx.Rollback(ctx)