Skip to content

fix: keep pagination iterators advancing past fully filtered pages - #1044

Open
vdusek wants to merge 4 commits into
v3from
fix/paginate-past-filtered-pages
Open

fix: keep pagination iterators advancing past fully filtered pages#1044
vdusek wants to merge 4 commits into
v3from
fix/paginate-past-filtered-pages

Conversation

@vdusek

@vdusek vdusek commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

TLDR

Description

The offset-based iterator stopped as soon as a page came back with no items, and advanced the offset by the number of items returned. Dataset filters (clean, skipEmpty, skipHidden) apply after offset and limit, so a page can scan up to limit rows while returning fewer, or none at all. listItems() used as an async iterable therefore ended early on a fully filtered page, and re-yielded rows an earlier page had already returned.

The iterator now paginates by the scanned count the API reports in x-apify-pagination-count, and by that number alone. items.length cannot stand in for it in either direction: filters leave it below the rows scanned and unwind can leave it above, so mixing the two would skip rows. PaginatedList.count stays items.length, since it is public and intentionally set that way; the scanned number travels with the page as a non-enumerable symbol property outside the public shape. Collection endpoints send no such header and fall back to items.length, so nothing about them changes.

The cursor iterators (listKeys(), listRequests(), paginateRequests()) are unchanged. The API never returns an empty page together with a cursor: the request queue listing hands out nextCursor only when it filled the whole page, and the key-value store listing derives nextExclusiveStartKey from the last key it returned.

Test plan

Regression tests for the fully filtered page, the duplicated offset, and unwind returning more items than rows scanned.

✍️ Drafted by Claude Code

@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Sep 8, 2026
@vdusek vdusek self-assigned this Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ There are broken links in the documentation.

See more at https://github.com/apify/apify-client-js/actions/runs/34473247015#summary-102857850927

@vdusek
vdusek marked this pull request as ready for review September 9, 2026 08:52
@vdusek
vdusek requested a review from barjin September 9, 2026 08:52

@barjin barjin left a comment

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.

Thank you @vdusek ,

I have a few findings ⬇️ , the first two are just notes (perhaps these changes are not necessary), the last one imo a bit more actionable.

Comment thread src/resource_clients/key_value_store.ts
Comment thread src/resource_clients/request_queue.ts
Comment thread src/base/api_client.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants