Skip to content

fix(admin): match /admin/receipts cursor key to the sort key (follow-up to #223)#230

Merged
smaramwbc merged 1 commit into
mainfrom
fix/admin-receipts-cursor-key
Jun 6, 2026
Merged

fix(admin): match /admin/receipts cursor key to the sort key (follow-up to #223)#230
smaramwbc merged 1 commit into
mainfrom
fix/admin-receipts-cursor-key

Conversation

@smaramwbc

Copy link
Copy Markdown
Owner

What

Follow-up to #223. That PR fixed the keyset-pagination mismatch in repo.list_receipts (/v1/receipts); the operator audit endpoint /admin/receipts (admin_list_receipts) carried the identical bug in its own inline query and was out of #223's scope.

It ordered by created_at DESC, receipt_id DESC but paginated with WHERE receipt_id < cursor. created_at (DB commit time) and receipt_id (app-side ULID) come from different clocks, so the ORDER BY and the cursor predicate disagree — silently skipping or re-showing receipts across pages, in an append-only audit trail that compliance reviewers walk page by page.

Fix

Order by receipt_id DESC alone, matching the cursor column (same fix as #223). One-line query change + comment.

Test

tests/integration/test_admin_receipts_pagination.py seeds receipts whose created_at and receipt_id orderings maximally disagree, walks every page via the real /admin/receipts route, and asserts each receipt appears exactly once. Verified locally: passes with the fix, fails without it.

admin_list_receipts ordered by created_at but paginated with
`receipt_id < cursor` — the same keyset-pagination mismatch fixed for
repo.list_receipts in #223, here on the operator audit endpoint. ULID
receipt_id encodes creation time, so ordering by it (matching the cursor
predicate) is sound newest-first; ordering by created_at (a different
clock) while cursoring on receipt_id silently dropped/duplicated receipts
across pages. Adds a regression test that walks a multi-page boundary.
@smaramwbc smaramwbc merged commit f51c661 into main Jun 6, 2026
5 checks passed
@smaramwbc smaramwbc deleted the fix/admin-receipts-cursor-key branch June 6, 2026 13:58
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.

1 participant