Skip to content

fix(bigquery): drop startIndex whenever a page token is sent - #18603

Merged
parthea merged 2 commits into
googleapis:mainfrom
abhishekacharya200:fix-bigquery-start-index-with-page-token
Oct 8, 2026
Merged

parthea merged 2 commits into
googleapis:mainfrom
abhishekacharya200:fix-bigquery-start-index-with-page-token

Conversation

@abhishekacharya200

Copy link
Copy Markdown
Contributor

Fixes #18601

RowIterator._get_next_page_response only removed startIndex from follow-up page requests when page_size was set. With only max_results and start_index, the server can still split the result into several pages (for example when a page would exceed the response size limit). The next request then sent both pageToken and startIndex, which the API rejects:

400 ... When using a page token, you cannot specify an arbitrary startIndex.

This drops startIndex whenever a page token is sent, regardless of page_size. The first request still carries startIndex, and the original params are not modified, so iterating the results again keeps working as before.

Added test_result_with_start_index_and_max_results_multi_page, which fails on main with the same pageToken + startIndex request from the issue and passes with this change. The full tests/unit suite passes locally (2396 passed), and black==23.7.0 reports no changes.

RowIterator only removed startIndex from follow-up page requests when page_size was set. With only max_results and start_index, the server can still split the result into several pages, and the next request then sent both pageToken and startIndex, which the API rejects with 400 'When using a page token, you cannot specify an arbitrary startIndex'.

Fixes googleapis#18601
@abhishekacharya200
abhishekacharya200 requested review from a team as code owners October 8, 2026 09:57
@abhishekacharya200
abhishekacharya200 requested review from tswast and removed request for a team October 8, 2026 09:57

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the logic for removing startIndex from query parameters during multi-page results in BigQuery. Instead of checking for page_size, it now removes startIndex when a page token is present, preventing conflicts when the server splits large results. A unit test was also added to verify this behavior. Feedback suggests improving readability by checking self.next_token is not None instead of checking if self._next_token is in params, as _next_token is a class attribute representing the parameter name string.

Comment thread packages/google-cloud-bigquery/google/cloud/bigquery/table.py Outdated
@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Oct 8, 2026
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Oct 8, 2026
@parthea

parthea commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @abhishekacharya200!

@parthea
parthea merged commit fc6eae3 into googleapis:main Oct 8, 2026
52 of 53 checks passed
@release-please release-please Bot mentioned this pull request Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Big Query RowIterator offset error

4 participants