Skip to content

Commit c191296

Browse files
feat: Update transaction.proto to include different lock modes (#845)
* feat: Update transaction.proto to include different lock modes PiperOrigin-RevId: 481838475 Source-Link: googleapis/googleapis@922f1f3 Source-Link: googleapis/googleapis-gen@bf32c6e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYmYzMmM2ZTQxM2Q0ZDdmZDNjOTliNzI1ZmFiNjUzZWI5ODNkOWRkNiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 0aa4cad commit c191296

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

google/cloud/spanner_v1/types/transaction.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,25 @@ class ReadWrite(proto.Message):
401401
r"""Message type to initiate a read-write transaction. Currently
402402
this transaction type has no options.
403403
404+
Attributes:
405+
read_lock_mode (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite.ReadLockMode):
406+
Read lock mode for the transaction.
404407
"""
405408

409+
class ReadLockMode(proto.Enum):
410+
r"""``ReadLockMode`` is used to set the read lock mode for read-write
411+
transactions.
412+
"""
413+
READ_LOCK_MODE_UNSPECIFIED = 0
414+
PESSIMISTIC = 1
415+
OPTIMISTIC = 2
416+
417+
read_lock_mode = proto.Field(
418+
proto.ENUM,
419+
number=1,
420+
enum="TransactionOptions.ReadWrite.ReadLockMode",
421+
)
422+
406423
class PartitionedDml(proto.Message):
407424
r"""Message type to initiate a Partitioned DML transaction."""
408425

tests/unit/gapic/spanner_v1/test_spanner.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,11 @@ def test_begin_transaction_flattened():
29262926
# using the keyword arguments to the method.
29272927
client.begin_transaction(
29282928
session="session_value",
2929-
options=transaction.TransactionOptions(read_write=None),
2929+
options=transaction.TransactionOptions(
2930+
read_write=transaction.TransactionOptions.ReadWrite(
2931+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
2932+
)
2933+
),
29302934
)
29312935

29322936
# Establish that the underlying call was made with the expected
@@ -2937,7 +2941,11 @@ def test_begin_transaction_flattened():
29372941
mock_val = "session_value"
29382942
assert arg == mock_val
29392943
arg = args[0].options
2940-
mock_val = transaction.TransactionOptions(read_write=None)
2944+
mock_val = transaction.TransactionOptions(
2945+
read_write=transaction.TransactionOptions.ReadWrite(
2946+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
2947+
)
2948+
)
29412949
assert arg == mock_val
29422950

29432951

@@ -2952,7 +2960,11 @@ def test_begin_transaction_flattened_error():
29522960
client.begin_transaction(
29532961
spanner.BeginTransactionRequest(),
29542962
session="session_value",
2955-
options=transaction.TransactionOptions(read_write=None),
2963+
options=transaction.TransactionOptions(
2964+
read_write=transaction.TransactionOptions.ReadWrite(
2965+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
2966+
)
2967+
),
29562968
)
29572969

29582970

@@ -2976,7 +2988,11 @@ async def test_begin_transaction_flattened_async():
29762988
# using the keyword arguments to the method.
29772989
response = await client.begin_transaction(
29782990
session="session_value",
2979-
options=transaction.TransactionOptions(read_write=None),
2991+
options=transaction.TransactionOptions(
2992+
read_write=transaction.TransactionOptions.ReadWrite(
2993+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
2994+
)
2995+
),
29802996
)
29812997

29822998
# Establish that the underlying call was made with the expected
@@ -2987,7 +3003,11 @@ async def test_begin_transaction_flattened_async():
29873003
mock_val = "session_value"
29883004
assert arg == mock_val
29893005
arg = args[0].options
2990-
mock_val = transaction.TransactionOptions(read_write=None)
3006+
mock_val = transaction.TransactionOptions(
3007+
read_write=transaction.TransactionOptions.ReadWrite(
3008+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3009+
)
3010+
)
29913011
assert arg == mock_val
29923012

29933013

@@ -3003,7 +3023,11 @@ async def test_begin_transaction_flattened_error_async():
30033023
await client.begin_transaction(
30043024
spanner.BeginTransactionRequest(),
30053025
session="session_value",
3006-
options=transaction.TransactionOptions(read_write=None),
3026+
options=transaction.TransactionOptions(
3027+
read_write=transaction.TransactionOptions.ReadWrite(
3028+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3029+
)
3030+
),
30073031
)
30083032

30093033

@@ -3168,7 +3192,11 @@ def test_commit_flattened():
31683192
mutations=[
31693193
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
31703194
],
3171-
single_use_transaction=transaction.TransactionOptions(read_write=None),
3195+
single_use_transaction=transaction.TransactionOptions(
3196+
read_write=transaction.TransactionOptions.ReadWrite(
3197+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3198+
)
3199+
),
31723200
)
31733201

31743202
# Establish that the underlying call was made with the expected
@@ -3184,7 +3212,9 @@ def test_commit_flattened():
31843212
]
31853213
assert arg == mock_val
31863214
assert args[0].single_use_transaction == transaction.TransactionOptions(
3187-
read_write=None
3215+
read_write=transaction.TransactionOptions.ReadWrite(
3216+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3217+
)
31883218
)
31893219

31903220

@@ -3203,7 +3233,11 @@ def test_commit_flattened_error():
32033233
mutations=[
32043234
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
32053235
],
3206-
single_use_transaction=transaction.TransactionOptions(read_write=None),
3236+
single_use_transaction=transaction.TransactionOptions(
3237+
read_write=transaction.TransactionOptions.ReadWrite(
3238+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3239+
)
3240+
),
32073241
)
32083242

32093243

@@ -3229,7 +3263,11 @@ async def test_commit_flattened_async():
32293263
mutations=[
32303264
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
32313265
],
3232-
single_use_transaction=transaction.TransactionOptions(read_write=None),
3266+
single_use_transaction=transaction.TransactionOptions(
3267+
read_write=transaction.TransactionOptions.ReadWrite(
3268+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3269+
)
3270+
),
32333271
)
32343272

32353273
# Establish that the underlying call was made with the expected
@@ -3245,7 +3283,9 @@ async def test_commit_flattened_async():
32453283
]
32463284
assert arg == mock_val
32473285
assert args[0].single_use_transaction == transaction.TransactionOptions(
3248-
read_write=None
3286+
read_write=transaction.TransactionOptions.ReadWrite(
3287+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3288+
)
32493289
)
32503290

32513291

@@ -3265,7 +3305,11 @@ async def test_commit_flattened_error_async():
32653305
mutations=[
32663306
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
32673307
],
3268-
single_use_transaction=transaction.TransactionOptions(read_write=None),
3308+
single_use_transaction=transaction.TransactionOptions(
3309+
read_write=transaction.TransactionOptions.ReadWrite(
3310+
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
3311+
)
3312+
),
32693313
)
32703314

32713315

0 commit comments

Comments
 (0)