Skip to content

Commit 69a9840

Browse files
Matej Čamajtseaver
authored andcommitted
Set next_page_token to none if there are no more result (googleapis#4349)
* Update _process_query_results_done Datastore test Response ``end_cursor`` might be non-empty as reported in googleapis#4347. * Set next_page_token to None using MoreResults enum (googleapis#4347) Depending on empty value of ``response_pb.batch.end_cursor`` is not reliable as the behaviour is not documented. It's better to check API response field ``moreResults``, see https://cloud.google.com/datastore/docs/reference/rpc/google.datastore.v1#google.datastore.v1.QueryResultBatch.
1 parent 2bf694b commit 69a9840

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

datastore/google/cloud/datastore/query.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626

2727

2828
_NOT_FINISHED = query_pb2.QueryResultBatch.NOT_FINISHED
29+
_NO_MORE_RESULTS = query_pb2.QueryResultBatch.NO_MORE_RESULTS
2930

3031
_FINISHED = (
31-
query_pb2.QueryResultBatch.NO_MORE_RESULTS,
32+
_NO_MORE_RESULTS,
3233
query_pb2.QueryResultBatch.MORE_RESULTS_AFTER_LIMIT,
3334
query_pb2.QueryResultBatch.MORE_RESULTS_AFTER_CURSOR,
3435
)
@@ -470,7 +471,7 @@ def _process_query_results(self, response_pb):
470471
"""
471472
self._skipped_results = response_pb.batch.skipped_results
472473

473-
if response_pb.batch.end_cursor == b'': # Empty-value for bytes.
474+
if response_pb.batch.more_results == _NO_MORE_RESULTS:
474475
self.next_page_token = None
475476
else:
476477
self.next_page_token = base64.urlsafe_b64encode(

datastore/tests/unit/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def test__process_query_results_done(self):
467467
entity_pbs = [
468468
_make_entity('World', 1234, 'PROJECT'),
469469
]
470-
cursor_as_bytes = b''
470+
cursor_as_bytes = b'\x9ai\xe7'
471471
skipped_results = 44
472472
more_results_enum = query_pb2.QueryResultBatch.NO_MORE_RESULTS
473473
response_pb = _make_query_response(

0 commit comments

Comments
 (0)