Skip to content

Commit

Permalink
fix: do not overwrite page_size with max_results when start_index is …
Browse files Browse the repository at this point in the history
…set (#1956)

* fix: do not overwrite page_size with max_results when start_index is set

* update test
  • Loading branch information
Linchin authored Jun 17, 2024
1 parent 7e522ee commit 7d0fcee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions google/cloud/bigquery/job/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,8 +1532,9 @@ def result( # type: ignore # (incompatible with supertype)
# Setting max_results should be equivalent to setting page_size with
# regards to allowing the user to tune how many results to download
# while we wait for the query to finish. See internal issue:
# 344008814.
if page_size is None and max_results is not None:
# 344008814. But if start_index is set, user is trying to access a
# specific page, so we don't need to set page_size. See issue #1950.
if page_size is None and max_results is not None and start_index is None:
page_size = max_results

# When timeout has default sentinel value ``object()``, do not pass
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/job/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,17 @@ def test_result_with_start_index(self):

start_index = 1

result = job.result(start_index=start_index)
# Verifies that page_size isn't overwritten by max_results when
# start_index is not None. See
# https://github.com/googleapis/python-bigquery/issues/1950
page_size = 10
max_results = 100

result = job.result(
page_size=page_size,
max_results=max_results,
start_index=start_index,
)

self.assertIsInstance(result, RowIterator)
self.assertEqual(result.total_rows, 5)
Expand All @@ -1665,6 +1675,9 @@ def test_result_with_start_index(self):
self.assertEqual(
tabledata_list_request[1]["query_params"]["startIndex"], start_index
)
self.assertEqual(
tabledata_list_request[1]["query_params"]["maxResults"], page_size
)

def test_result_error(self):
from google.cloud import exceptions
Expand Down

0 comments on commit 7d0fcee

Please sign in to comment.