Repository navigation
Conversation
Pager and AsyncPager raised IndexError when a page came back empty but the response still had a next_page_token, so items on later pages were never returned. List APIs may return fewer items than page_size, including zero, before the end of the collection (AIP-158), which is common with filtered list calls. Fixes googleapis#3429
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PagerandAsyncPagercrashed withIndexError: list index out of rangewhen a list page came back empty but the response still carried anext_page_token, so items on later pages were silently unreachable.Google list APIs are allowed to return fewer items than
page_size, including zero, before the end of the collection (AIP-158). This is common with filters, where one scanned page can match nothing.Root cause
__next__/__anext__fetched the next page once when the current page was exhausted, then indexed into it unconditionally:Fix
Loop instead of a single fetch: keep pulling pages while the current one is exhausted and a
next_page_tokenexists. Iteration still stops when a response arrives without a token.Tests
New
google/genai/tests/pagers/test_pagers.py, reproducing the exact scenario from the issue with token-keyed mock pages:test_pager_iterates_past_empty_page: sync iteration yields['files/a', 'files/b']across the empty middle pagetest_pager_stops_after_last_empty_page: iteration still terminates when the empty page is the last onetest_async_pager_iterates_past_empty_page: same forAsyncPagerRed-green verified: the sync test fails with
IndexErroron unpatchedmainand all 3 pass with the fix.Fixes #3429