Skip to content

Commit

Permalink
fix: Using end_cursor instead of skipped_cursor in Iterator to fix ra…
Browse files Browse the repository at this point in the history
…re 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>
  • Loading branch information
3 people committed Jul 30, 2024
1 parent e760614 commit 4982f9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion google/cloud/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def _next_page(self):
old_query_pb = query_pb
query_pb = query_pb2.Query()
query_pb._pb.CopyFrom(old_query_pb._pb) # copy for testability
query_pb.start_cursor = response_pb.batch.skipped_cursor
query_pb.start_cursor = response_pb.batch.end_cursor
query_pb.offset -= response_pb.batch.skipped_results

request = {
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,8 @@ def test_iterator__next_page_no_more(database_id):


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

project = "prujekt"
skipped_1 = 100
skipped_cursor_1 = b"DEADBEEF"
end_cursor_1 = b"DEADBEEF"
skipped_2 = 50
skipped_cursor_2 = b"FACEDACE"
end_cursor_2 = b"FACEDACE"

more_enum = query_pb2.QueryResultBatch.MoreResultsType.NOT_FINISHED

result_1 = _make_query_response([], b"", more_enum, skipped_1)
result_1.batch.skipped_cursor = skipped_cursor_1
result_1.batch.end_cursor = end_cursor_1
result_2 = _make_query_response([], b"", more_enum, skipped_2)
result_2.batch.skipped_cursor = skipped_cursor_2
result_2.batch.end_cursor = end_cursor_2

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

query_1 = query_pb2.Query(offset=offset)
query_2 = query_pb2.Query(
start_cursor=skipped_cursor_1, offset=(offset - skipped_1)
)
query_2 = query_pb2.Query(start_cursor=end_cursor_1, offset=(offset - skipped_1))
expected_calls = []
for query in [query_1, query_2]:
expected_request = {
Expand Down

0 comments on commit 4982f9a

Please sign in to comment.