Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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