fix(spanner): use nil mutation for BeginTransaction The BeginTransaction function requires a mutation to be passed in. This should be nil when using regular sessions.
diff --git a/spanner/client.go b/spanner/client.go index 3ad333c..b453194 100644 --- a/spanner/client.go +++ b/spanner/client.go
@@ -1035,7 +1035,9 @@ t.txReadOnly.ro = c.ro t.txReadOnly.disableRouteToLeader = c.disableRouteToLeader t.txOpts = c.txo.merge(options) - if err := t.begin(ctx); err != nil { + // A mutation should only be included in the BeginTransaction RPC + // when using multiplexed sessions. + if err := t.begin(ctx /*mutation=*/, nil); err != nil { sh.recycle() return nil, err }
diff --git a/spanner/client_test.go b/spanner/client_test.go index 946d8c5..6393625 100644 --- a/spanner/client_test.go +++ b/spanner/client_test.go
@@ -1954,15 +1954,17 @@ t.Fatal("missing transaction id") } } - // Verify that the next transaction fails, as the pool is exhausted and we have disabled the prepareFunc. + // Verify that the next transaction fails, as the pool is exhausted, and we have disabled the prepareFunc. + ctx, cancel := context.WithTimeout(ctx, 5*time.Millisecond) + defer cancel() _, err = txPool.RunTransaction(ctx, func(ctx context.Context, transaction *ReadWriteTransaction) error { return nil }) if err == nil { t.Fatal("missing error for last transaction") } - if g, w := ErrCode(err), codes.ResourceExhausted; g != w { - t.Fatalf("error code mismatch\n Got %v\nWant: %v", g, w) + if g, w := err, context.DeadlineExceeded; !errors.Is(g, w) { + t.Fatalf("error mismatch\n Got: %v\nWant: %v", g, w) } } @@ -2039,15 +2041,17 @@ t.Fatal("missing transaction id") } } - // Verify that the next transaction fails, as the pool is exhausted and we have disabled the prepareFunc. + // Verify that the next transaction fails, as the pool is exhausted, and we have disabled the prepareFunc. + ctx, cancel := context.WithTimeout(ctx, 5*time.Millisecond) + defer cancel() _, err = client.ReadWriteTransaction(ctx, func(ctx context.Context, transaction *ReadWriteTransaction) error { return nil }) if err == nil { t.Fatal("missing error for last transaction") } - if g, w := ErrCode(err), codes.ResourceExhausted; g != w { - t.Fatalf("error code mismatch\n Got %v\nWant: %v", g, w) + if g, w := err, context.DeadlineExceeded; !errors.Is(g, w) { + t.Fatalf("error mismatch\n Got: %v\nWant: %v", g, w) } }