Skip to content

Add iter_export_pages to follow export cursors - #52

Merged
mohsen1 merged 3 commits into
prooflinedev:mainfrom
Mamut446:feat/iter-export-pages
Nov 17, 2026
Merged

mohsen1 merged 3 commits into
prooflinedev:mainfrom
Mamut446:feat/iter-export-pages

Conversation

@Mamut446

Copy link
Copy Markdown
Contributor

Who it helps: anyone pulling a full export window into a warehouse or spreadsheet. Today export_reviews returns one page and the README says to loop on next_cursor yourself, resending the same dataset, window, format and grouping each time. That's easy to get wrong: drop group_by on page 2 and the cursor is refused, or a bad cursor loops forever.

What it does: iter_export_pages on both clients yields each ExportPage in order and stops after the page with no next cursor. cursor= resumes from a saved position.

with ProoflineClient() as client:
    for page in client.iter_export_pages(org_id, "spend", from_time=start, to_time=end, group_by="repository"):
        for row in page.rows:
            ...

Decisions

  • Yields pages, not rows. Each CSV page carries its own header and keeps text, settled_until and next_cursor, so callers can checkpoint the cursor or write raw pages. Rows are one loop away.
  • Same guardrails as iter_reviews: max_pages (default 100, max 1000), a repeated or empty cursor raises urn:proofline:sdk:invalid-pagination, going past the bound raises urn:proofline:sdk:pagination-limit. _pagination_limit now takes a subject so the message says "Export" here; the review message is unchanged.
  • It calls export_reviews, so request validation, transport and error handling stay in one place.

How I verified it

  • 16 new test cases in tests/test_http.py across sync and async: follows cursors with the same filters, resumes from a saved cursor, refuses a repeated or empty cursor, stops at max_pages, validates max_pages. All 22 export tests pass.
  • Full suite: 155 passed. test_new_public_operation also fails on a clean checkout in my environment because it shells out to the generator.
  • ruff check is clean; mypy reports only the 5 errors already on main.
  • README: short section under Review exports.

@Mamut446

Copy link
Copy Markdown
Contributor Author

Thanks for re-running it. The failure was mine: the contract check keeps a list of allowed client helpers and I hadn't added iter_export_pages to it. Fixed in b4d3866, and the full scripts/check.py passes locally.

mohsen1 commented Nov 17, 2026

Copy link
Copy Markdown
Member

Codex review: The helper-registration fix is now green. Before yielding a page, validate its continuation cursor so a cyclic response cannot deliver duplicate rows to callers; add a regression asserting that the offending page is never yielded. This overlaps #27, our preferred bounded iterator, so please consolidate around one implementation.

Mamut446 and others added 3 commits November 17, 2026 14:33
Yields each export page in order on the sync and async clients, sending
the same dataset, window, format and grouping on every request, and stops
after the page without a next cursor. Same guardrails as iter_reviews:
max_pages bound, repeated or empty cursor raises invalid-pagination.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V9GvJaWFKxjgK1vyZ27mhr
…with an invalid cursor

Adopt the bounded export iterator from prooflinedev#27 unchanged, rebased on current main:
the continuation cursor is validated before its page is yielded, and max_pages
rejects booleans and non-integers. Take prooflinedev#27's tests in place of this branch's.

Add a regression for sync and async clients asserting that the page carrying an
empty, resumed, repeated or cyclic cursor is never yielded.

Co-authored-by: AI1120 <133474218+AI1120@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V9GvJaWFKxjgK1vyZ27mhr
@Mamut446
Mamut446 force-pushed the feat/iter-export-pages branch from b4d3866 to e6fa891 Compare November 17, 2026 14:36
@Mamut446

Copy link
Copy Markdown
Contributor Author

Done in e6fa891. This branch now carries #27's iterator unchanged, rebased on current main and credited to its author in the commit: the continuation cursor is checked before its page is yielded, and max_pages rejects booleans and non-integers. I took #27's tests in place of mine and added the regression you asked for: for sync and async clients, the page carrying an empty, resumed, repeated or cyclic cursor is never yielded. It fails on the old order. Full scripts/check.py passes, 216 tests. If you'd rather merge #27 itself, happy to close this one.

@mohsen1
mohsen1 merged commit 31b55f7 into prooflinedev:main Nov 17, 2026
1 of 2 checks passed
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.

2 participants