Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit906d026

Browse files
feat: new transaction options for datastoreV1 (#402)
* feat: new transaction options for datastoreV1PiperOrigin-RevId: 501960571Source-Link:googleapis/googleapis@d4599adSource-Link:googleapis/googleapis-gen@02ff42cCopy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDJmZjQyY2YwMzA5NjViOTAwNjI0M2M2OTdlNzYxZmRjYWJiOGNhMSJ9* 🦉 Updates from OwlBot post-processorSeehttps://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.mdCo-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent1043ba3 commit906d026

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

‎google/cloud/datastore_v1/types/datastore.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class LookupResponse(proto.Message):
107107
resource constraints. The order of results in
108108
this field is undefined and has no relation to
109109
the order of the keys in the input.
110+
transaction (bytes):
111+
The identifier of the transaction that was started as part
112+
of this Lookup request.
113+
114+
Set only when [ReadOptions.begin_transaction][] was set in
115+
[LookupRequest.read_options][google.datastore.v1.LookupRequest.read_options].
110116
read_time (google.protobuf.timestamp_pb2.Timestamp):
111117
The time at which these entities were read or
112118
found missing.
@@ -127,6 +133,10 @@ class LookupResponse(proto.Message):
127133
number=3,
128134
message=entity.Key,
129135
)
136+
transaction:bytes=proto.Field(
137+
proto.BYTES,
138+
number=5,
139+
)
130140
read_time:timestamp_pb2.Timestamp=proto.Field(
131141
proto.MESSAGE,
132142
number=7,
@@ -215,6 +225,12 @@ class RunQueryResponse(proto.Message):
215225
query (google.cloud.datastore_v1.types.Query):
216226
The parsed form of the ``GqlQuery`` from the request, if it
217227
was set.
228+
transaction (bytes):
229+
The identifier of the transaction that was started as part
230+
of this RunQuery request.
231+
232+
Set only when [ReadOptions.begin_transaction][] was set in
233+
[RunQueryRequest.read_options][google.datastore.v1.RunQueryRequest.read_options].
218234
"""
219235

220236
batch:gd_query.QueryResultBatch=proto.Field(
@@ -227,6 +243,10 @@ class RunQueryResponse(proto.Message):
227243
number=2,
228244
message=gd_query.Query,
229245
)
246+
transaction:bytes=proto.Field(
247+
proto.BYTES,
248+
number=5,
249+
)
230250

231251

232252
classRunAggregationQueryRequest(proto.Message):
@@ -311,6 +331,12 @@ class RunAggregationQueryResponse(proto.Message):
311331
query (google.cloud.datastore_v1.types.AggregationQuery):
312332
The parsed form of the ``GqlQuery`` from the request, if it
313333
was set.
334+
transaction (bytes):
335+
The identifier of the transaction that was started as part
336+
of this RunAggregationQuery request.
337+
338+
Set only when [ReadOptions.begin_transaction][] was set in
339+
[RunAggregationQueryRequest.read_options][google.datastore.v1.RunAggregationQueryRequest.read_options].
314340
"""
315341

316342
batch:aggregation_result.AggregationResultBatch=proto.Field(
@@ -323,6 +349,10 @@ class RunAggregationQueryResponse(proto.Message):
323349
number=2,
324350
message=gd_query.AggregationQuery,
325351
)
352+
transaction:bytes=proto.Field(
353+
proto.BYTES,
354+
number=5,
355+
)
326356

327357

328358
classBeginTransactionRequest(proto.Message):
@@ -416,6 +446,10 @@ class CommitRequest(proto.Message):
416446
r"""The request for
417447
[Datastore.Commit][google.datastore.v1.Datastore.Commit].
418448
449+
This message has `oneof`_ fields (mutually exclusive fields).
450+
For each oneof, at most one member field can be set at the same time.
451+
Setting any member of the oneof automatically clears all other
452+
members.
419453
420454
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
421455
@@ -436,6 +470,15 @@ class CommitRequest(proto.Message):
436470
commit. A transaction identifier is returned by a call to
437471
[Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
438472
473+
This field is a member of `oneof`_ ``transaction_selector``.
474+
single_use_transaction (google.cloud.datastore_v1.types.TransactionOptions):
475+
Options for beginning a new transaction for this request.
476+
The transaction is committed when the request completes. If
477+
specified,
478+
[TransactionOptions.mode][google.datastore.v1.TransactionOptions.mode]
479+
must be
480+
[TransactionOptions.ReadWrite][google.datastore.v1.TransactionOptions.ReadWrite].
481+
439482
This field is a member of `oneof`_ ``transaction_selector``.
440483
mutations (MutableSequence[google.cloud.datastore_v1.types.Mutation]):
441484
The mutations to perform.
@@ -478,6 +521,12 @@ class Mode(proto.Enum):
478521
number=1,
479522
oneof="transaction_selector",
480523
)
524+
single_use_transaction:"TransactionOptions"=proto.Field(
525+
proto.MESSAGE,
526+
number=10,
527+
oneof="transaction_selector",
528+
message="TransactionOptions",
529+
)
481530
mutations:MutableSequence["Mutation"]=proto.RepeatedField(
482531
proto.MESSAGE,
483532
number=6,
@@ -769,6 +818,16 @@ class ReadOptions(proto.Message):
769818
transaction identifier is returned by a call to
770819
[Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
771820
821+
This field is a member of `oneof`_ ``consistency_type``.
822+
new_transaction (google.cloud.datastore_v1.types.TransactionOptions):
823+
Options for beginning a new transaction for this request.
824+
825+
The new transaction identifier will be returned in the
826+
corresponding response as either
827+
[LookupResponse.transaction][google.datastore.v1.LookupResponse.transaction]
828+
or
829+
[RunQueryResponse.transaction][google.datastore.v1.RunQueryResponse.transaction].
830+
772831
This field is a member of `oneof`_ ``consistency_type``.
773832
read_time (google.protobuf.timestamp_pb2.Timestamp):
774833
Reads entities as they were at the given
@@ -796,6 +855,12 @@ class ReadConsistency(proto.Enum):
796855
number=2,
797856
oneof="consistency_type",
798857
)
858+
new_transaction:"TransactionOptions"=proto.Field(
859+
proto.MESSAGE,
860+
number=3,
861+
oneof="consistency_type",
862+
message="TransactionOptions",
863+
)
799864
read_time:timestamp_pb2.Timestamp=proto.Field(
800865
proto.MESSAGE,
801866
number=4,

‎scripts/fixup_datastore_v1_keywords.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class datastoreCallTransformer(cst.CSTTransformer):
4141
METHOD_TO_PARAMS:Dict[str,Tuple[str]]= {
4242
'allocate_ids': ('project_id','keys','database_id', ),
4343
'begin_transaction': ('project_id','database_id','transaction_options', ),
44-
'commit': ('project_id','database_id','mode','transaction','mutations', ),
44+
'commit': ('project_id','database_id','mode','transaction','single_use_transaction','mutations', ),
4545
'lookup': ('project_id','keys','database_id','read_options', ),
4646
'reserve_ids': ('project_id','keys','database_id', ),
4747
'rollback': ('project_id','transaction','database_id', ),

‎tests/unit/gapic/datastore_v1/test_datastore.py‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ def test_lookup(request_type, transport: str = "grpc"):
683683
# Mock the actual call within the gRPC stub, and fake the request.
684684
withmock.patch.object(type(client.transport.lookup),"__call__")ascall:
685685
# Designate an appropriate return value for the call.
686-
call.return_value=datastore.LookupResponse()
686+
call.return_value=datastore.LookupResponse(
687+
transaction=b"transaction_blob",
688+
)
687689
response=client.lookup(request)
688690

689691
# Establish that the underlying gRPC stub method was called.
@@ -693,6 +695,7 @@ def test_lookup(request_type, transport: str = "grpc"):
693695

694696
# Establish that the response is the type that we expect.
695697
assertisinstance(response,datastore.LookupResponse)
698+
assertresponse.transaction==b"transaction_blob"
696699

697700

698701
deftest_lookup_empty_call():
@@ -728,7 +731,9 @@ async def test_lookup_async(
728731
withmock.patch.object(type(client.transport.lookup),"__call__")ascall:
729732
# Designate an appropriate return value for the call.
730733
call.return_value=grpc_helpers_async.FakeUnaryUnaryCall(
731-
datastore.LookupResponse()
734+
datastore.LookupResponse(
735+
transaction=b"transaction_blob",
736+
)
732737
)
733738
response=awaitclient.lookup(request)
734739

@@ -739,6 +744,7 @@ async def test_lookup_async(
739744

740745
# Establish that the response is the type that we expect.
741746
assertisinstance(response,datastore.LookupResponse)
747+
assertresponse.transaction==b"transaction_blob"
742748

743749

744750
@pytest.mark.asyncio
@@ -941,7 +947,9 @@ def test_run_query(request_type, transport: str = "grpc"):
941947
# Mock the actual call within the gRPC stub, and fake the request.
942948
withmock.patch.object(type(client.transport.run_query),"__call__")ascall:
943949
# Designate an appropriate return value for the call.
944-
call.return_value=datastore.RunQueryResponse()
950+
call.return_value=datastore.RunQueryResponse(
951+
transaction=b"transaction_blob",
952+
)
945953
response=client.run_query(request)
946954

947955
# Establish that the underlying gRPC stub method was called.
@@ -951,6 +959,7 @@ def test_run_query(request_type, transport: str = "grpc"):
951959

952960
# Establish that the response is the type that we expect.
953961
assertisinstance(response,datastore.RunQueryResponse)
962+
assertresponse.transaction==b"transaction_blob"
954963

955964

956965
deftest_run_query_empty_call():
@@ -986,7 +995,9 @@ async def test_run_query_async(
986995
withmock.patch.object(type(client.transport.run_query),"__call__")ascall:
987996
# Designate an appropriate return value for the call.
988997
call.return_value=grpc_helpers_async.FakeUnaryUnaryCall(
989-
datastore.RunQueryResponse()
998+
datastore.RunQueryResponse(
999+
transaction=b"transaction_blob",
1000+
)
9901001
)
9911002
response=awaitclient.run_query(request)
9921003

@@ -997,6 +1008,7 @@ async def test_run_query_async(
9971008

9981009
# Establish that the response is the type that we expect.
9991010
assertisinstance(response,datastore.RunQueryResponse)
1011+
assertresponse.transaction==b"transaction_blob"
10001012

10011013

10021014
@pytest.mark.asyncio
@@ -1067,7 +1079,9 @@ def test_run_aggregation_query(request_type, transport: str = "grpc"):
10671079
type(client.transport.run_aggregation_query),"__call__"
10681080
)ascall:
10691081
# Designate an appropriate return value for the call.
1070-
call.return_value=datastore.RunAggregationQueryResponse()
1082+
call.return_value=datastore.RunAggregationQueryResponse(
1083+
transaction=b"transaction_blob",
1084+
)
10711085
response=client.run_aggregation_query(request)
10721086

10731087
# Establish that the underlying gRPC stub method was called.
@@ -1077,6 +1091,7 @@ def test_run_aggregation_query(request_type, transport: str = "grpc"):
10771091

10781092
# Establish that the response is the type that we expect.
10791093
assertisinstance(response,datastore.RunAggregationQueryResponse)
1094+
assertresponse.transaction==b"transaction_blob"
10801095

10811096

10821097
deftest_run_aggregation_query_empty_call():
@@ -1116,7 +1131,9 @@ async def test_run_aggregation_query_async(
11161131
)ascall:
11171132
# Designate an appropriate return value for the call.
11181133
call.return_value=grpc_helpers_async.FakeUnaryUnaryCall(
1119-
datastore.RunAggregationQueryResponse()
1134+
datastore.RunAggregationQueryResponse(
1135+
transaction=b"transaction_blob",
1136+
)
11201137
)
11211138
response=awaitclient.run_aggregation_query(request)
11221139

@@ -1127,6 +1144,7 @@ async def test_run_aggregation_query_async(
11271144

11281145
# Establish that the response is the type that we expect.
11291146
assertisinstance(response,datastore.RunAggregationQueryResponse)
1147+
assertresponse.transaction==b"transaction_blob"
11301148

11311149

11321150
@pytest.mark.asyncio

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp