Skip to content

feat!: iterate only the current page when looping over a list response - #744

Open
tribble wants to merge 3 commits into
mainfrom
feat/page-local-iteration
Open

tribble wants to merge 3 commits into
mainfrom
feat/page-local-iteration

Conversation

@tribble

@tribble tribble commented Oct 3, 2026 •

Copy link
Copy Markdown

I found that looping over a list response silently fetched every remaining page.

  • for x in page / async for x in page now yield only the current page's items and make no further requests.
  • page.auto_paging_iter() remains the explicit way to iterate across all pages (forward).

Migration: replace for x in page with for x in page.auto_paging_iter() (likewise async for) to keep iterating across pages.

Test plan

  • Red: this PR's tests run against main's pagination implementation at 9bbc82d — mise x uv -- uv run pytest -q tests/test_pagination.py -k PageLocalIteration — both the sync and async test fail with WorkOSTimeoutError, because plain iteration issues a second HTTP request the mock has no response queued for.
  • Green on this branch: the same command passes — both tests assert the page yields its two items in order and that exactly one HTTP request was made, even with list_metadata.after set.

@tribble
tribble requested review from a team as code owners October 3, 2026 06:12
@tribble
tribble requested a review from awolfden October 3, 2026 06:12
@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High impact] The PR appears safe to merge; no outstanding finding or actionable new defect was established.

Summary

The PR makes direct sync and async page iteration yield only the current page’s items, while retaining cross-page traversal through auto_paging_iter().

  • Follow-up requests now clear the original before cursor when advancing with after.
  • Tests cover both iteration modes and the follow-up request parameters; the README adds v11 migration guidance.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Page[Page response] --> Direct[Direct iteration]
  Direct --> Items[Current page items only]
  Page --> Auto[auto_paging_iter]
  Auto --> Items
  Auto -->|after cursor| Next[Fetch next page]
  Next --> Auto
Loading

Reviews (2) · Last reviewed commit: "Merge origin/main into feat/page-local-i..." · Reviewed by Greptile

Comment thread docs/V6_MIGRATION_GUIDE.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants