Skip to content

Commit

Permalink
return null TxControl on Completed Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Sep 25, 2024
1 parent 06c57c7 commit 2dc9c7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Ydb.Sdk/src/Ado/YdbTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public sealed class YdbTransaction : DbTransaction
internal bool Completed { get; set; }
internal bool Failed { get; set; }

internal TransactionControl TransactionControl => TxId == null
? new TransactionControl { BeginTx = _txMode.TransactionSettings() }
: new TransactionControl { TxId = TxId };
internal TransactionControl? TransactionControl => Completed || Failed
? null
: TxId == null
? new TransactionControl { BeginTx = _txMode.TransactionSettings() }
: new TransactionControl { TxId = TxId };

internal YdbTransaction(YdbConnection ydbConnection, TxMode txMode)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Ydb.Sdk/tests/Ado/YdbExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public async Task IsTransient_WhenAborted_ReturnTrueAndMakeEmptyRollback()
{
CommandText = $"DROP TABLE {bankTable}"
}.ExecuteNonQueryAsync();
Assert.Equal("Status: NotFound", Assert.Throws<YdbException>(() => ydbCommand.Transaction.Commit()).Message);
Assert.Equal("This YdbTransaction has completed; it is no longer usable",
Assert.Throws<InvalidOperationException>(() => ydbCommand.Transaction.Commit()).Message);

await ydbCommand.Transaction!.RollbackAsync();
Assert.Equal("This YdbTransaction has completed; it is no longer usable",
Expand Down

0 comments on commit 2dc9c7d

Please sign in to comment.