Skip to content

Commit 10ee79e

Browse files
authored
fix(Spanner): ensure tag is passed to BeginTransactionRequest (#8935)
1 parent 4f1f0fa commit 10ee79e

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Spanner/src/Transaction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,14 @@ public function commit(array $options = []): Timestamp
444444
'requestOptions' => $this->requestOptions,
445445
'transactionOptions' => $this->transactionOptions,
446446
'singleUse' => $this->transactionSelector['singleUse'] ?? null,
447+
'tag' => $this->tag ?? null,
447448
]);
448449
if (!empty($mutations)) {
449450
// Set the mutation key if we have mutations but do not have a precommit token
450451
$mutationKey = $mutations[array_rand($mutations)];
451452
$operationTransactionOptions['mutationKey'] = $mutationKey;
452453
}
454+
453455
// Execute the beginTransaction RPC.
454456
$transaction = $this->operation->transaction($this->session, $operationTransactionOptions);
455457
// Set the transaction ID of the current transaction.

Spanner/tests/Unit/DatabaseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,32 @@ public function testRunTransactionAborted()
921921
});
922922
}
923923

924+
public function testRunTransactionWithTagOption()
925+
{
926+
$this->spannerClient->beginTransaction(
927+
Argument::that(function (BeginTransactionRequest $request) {
928+
$reqOptions = $request->getRequestOptions();
929+
$this->assertNotNull($reqOptions);
930+
$this->assertEquals(self::TRANSACTION_TAG, $reqOptions->getTransactionTag());
931+
return true;
932+
}),
933+
Argument::type('array')
934+
)
935+
->shouldBeCalledOnce()
936+
->willReturn(new TransactionProto(['id' => self::TRANSACTION]));
937+
938+
$this->spannerClient->commit(
939+
Argument::type(CommitRequest::class),
940+
Argument::type('array')
941+
)
942+
->shouldBeCalled()
943+
->willReturn($this->commitResponse());
944+
945+
$this->database->runTransaction(function (Transaction $t) {
946+
$t->commit();
947+
}, ['tag' => self::TRANSACTION_TAG]);
948+
}
949+
924950
public function testTransaction()
925951
{
926952
$this->spannerClient->beginTransaction(

0 commit comments

Comments
 (0)