Skip to content

fix: honor max for singular items in PagedResults#each - #28073

Open
torreypayne wants to merge 2 commits into
mainfrom
fix/paged-results-singular-max
Open

torreypayne wants to merge 2 commits into
mainfrom
fix/paged-results-singular-max

Conversation

@torreypayne

Copy link
Copy Markdown
Member

PagedResults#each increments item_count and checks max in the Array and Hash branches, but the singular-item branch only yields. A sequence of singular pages therefore ignores max and yields every item; it also keeps fetching pages past the limit.

This applies the same counting and limit check to the singular branch, and adds specs for both the yielded items and the pages fetched (max: 2 over three singular pages now yields two items and fetches two pages).

Fixes #27759. Thanks to @OskarEichler for the report and analysis.

@torreypayne
torreypayne requested a review from a team as a code owner October 1, 2026 21:37
@quartzmo
quartzmo self-requested a review October 1, 2026 22:27
expect(service.fetch_all(max: 5) { |token| responses[token] } ).to contain_exactly('a', 'b', 'c', 'd', 'e')
end

it 'should allow limiting the number of singular items to fetch' do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would a quick unit test for max: 0 be worth having here?

A zero max request is fringe for sure, but fetch_all(max: 0, items: :singular) appears to have yielded one item before this change and now yields none after it.

@torreypayne torreypayne Oct 2, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch

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.

google-apis-core: singular PagedResults ignores max

2 participants