Skip to content

Commit 4982f9a

Browse files
gkevinzhenggcf-owl-bot[bot]daniel-sanche
authored
fix: Using end_cursor instead of skipped_cursor in Iterator to fix rare bug. (#552)
* fix: Using end_cursor instead of skipped_cursor in Iterator to fix rare bug. * 🦉 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> Co-authored-by: Daniel Sanche <sanche@google.com>
1 parent e760614 commit 4982f9a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

google/cloud/datastore/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ def _next_page(self):
825825
old_query_pb = query_pb
826826
query_pb = query_pb2.Query()
827827
query_pb._pb.CopyFrom(old_query_pb._pb) # copy for testability
828-
query_pb.start_cursor = response_pb.batch.skipped_cursor
828+
query_pb.start_cursor = response_pb.batch.end_cursor
829829
query_pb.offset -= response_pb.batch.skipped_results
830830

831831
request = {

tests/unit/test_query.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,8 @@ def test_iterator__next_page_no_more(database_id):
10191019

10201020

10211021
@pytest.mark.parametrize("database_id", [None, "somedb"])
1022-
def test_iterator__next_page_w_skipped_lt_offset(database_id):
1022+
@pytest.mark.parametrize("skipped_cursor_1", [b"DEADBEEF", b""])
1023+
def test_iterator__next_page_w_skipped_lt_offset(skipped_cursor_1, database_id):
10231024
from google.api_core import page_iterator
10241025
from google.cloud.datastore_v1.types import datastore as datastore_pb2
10251026
from google.cloud.datastore_v1.types import entity as entity_pb2
@@ -1028,16 +1029,17 @@ def test_iterator__next_page_w_skipped_lt_offset(database_id):
10281029

10291030
project = "prujekt"
10301031
skipped_1 = 100
1031-
skipped_cursor_1 = b"DEADBEEF"
1032+
end_cursor_1 = b"DEADBEEF"
10321033
skipped_2 = 50
1033-
skipped_cursor_2 = b"FACEDACE"
1034+
end_cursor_2 = b"FACEDACE"
10341035

10351036
more_enum = query_pb2.QueryResultBatch.MoreResultsType.NOT_FINISHED
10361037

10371038
result_1 = _make_query_response([], b"", more_enum, skipped_1)
10381039
result_1.batch.skipped_cursor = skipped_cursor_1
1040+
result_1.batch.end_cursor = end_cursor_1
10391041
result_2 = _make_query_response([], b"", more_enum, skipped_2)
1040-
result_2.batch.skipped_cursor = skipped_cursor_2
1042+
result_2.batch.end_cursor = end_cursor_2
10411043

10421044
ds_api = _make_datastore_api(result_1, result_2)
10431045
client = _Client(project, datastore_api=ds_api, database=database_id)
@@ -1055,9 +1057,7 @@ def test_iterator__next_page_w_skipped_lt_offset(database_id):
10551057
read_options = datastore_pb2.ReadOptions()
10561058

10571059
query_1 = query_pb2.Query(offset=offset)
1058-
query_2 = query_pb2.Query(
1059-
start_cursor=skipped_cursor_1, offset=(offset - skipped_1)
1060-
)
1060+
query_2 = query_pb2.Query(start_cursor=end_cursor_1, offset=(offset - skipped_1))
10611061
expected_calls = []
10621062
for query in [query_1, query_2]:
10631063
expected_request = {

0 commit comments

Comments
 (0)