Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 60e384f

Browse files
committed
fix: update 'HTTPDatastoreAPI.run_query' to follow request-only pattern
Toward #124
1 parent 685ec12 commit 60e384f

2 files changed

Lines changed: 18 additions & 31 deletions

File tree

‎google/cloud/datastore/_http.py‎

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -180,42 +180,23 @@ def lookup(self, project_id, keys, read_options=None):
180180
_datastore_pb2.LookupResponse,
181181
)
182182

183-
def run_query(
184-
self, project_id, partition_id, read_options=None, query=None, gql_query=None
185-
):
183+
def run_query(self, request):
186184
"""Perform a ``runQuery`` request.
187185
188-
:type project_id: str
189-
:param project_id: The project to connect to. This is
190-
usually your project name in the cloud console.
191-
192-
:type partition_id: :class:`.entity_pb2.PartitionId`
193-
:param partition_id: Partition ID corresponding to an optional
194-
namespace and project ID.
195-
196-
:type read_options: :class:`.datastore_pb2.ReadOptions`
197-
:param read_options: (Optional) The options for this query. Contains
198-
either the transaction for the read or
199-
``STRONG`` or ``EVENTUAL`` read consistency.
200-
201-
:type query: :class:`.query_pb2.Query`
202-
:param query: (Optional) The query protobuf to run. At most one of
203-
``query`` and ``gql_query`` can be specified.
204-
205-
:type gql_query: :class:`.query_pb2.GqlQuery`
206-
:param gql_query: (Optional) The GQL query to run. At most one of
207-
``query`` and ``gql_query`` can be specified.
186+
:type request: :class:`_datastore_pb2.BeginTransactionRequest` or dict
187+
:param request:
188+
Parameter bundle for API request.
208189
209190
:rtype: :class:`.datastore_pb2.RunQueryResponse`
210191
:returns: The returned protobuf response object.
211192
"""
212-
request_pb = _datastore_pb2.RunQueryRequest(
213-
project_id=project_id,
214-
partition_id=partition_id,
215-
read_options=read_options,
216-
query=query,
217-
gql_query=gql_query,
218-
)
193+
if not isinstance(request, _datastore_pb2.RunQueryRequest):
194+
request_pb = _datastore_pb2.RunQueryRequest(**request)
195+
else:
196+
request_pb = request
197+
198+
project_id = request_pb.project_id
199+
219200
return _rpc(
220201
self.client._http,
221202
project_id,

‎tests/unit/test__http.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,14 @@ def _run_query_helper(
347347
spec=["_http", "_base_url", "_client_info"],
348348
)
349349
ds_api = self._make_one(client)
350+
request = {
351+
"project_id": project,
352+
"partition_id": partition_id,
353+
"read_options": read_options,
354+
"query": query_pb,
355+
}
350356

351-
response = ds_api.run_query(project, partition_id, read_options, query=query_pb)
357+
response = ds_api.run_query(request=request)
352358

353359
self.assertEqual(response, rsp_pb._pb)
354360

0 commit comments

Comments
 (0)