fix(admin): match /admin/receipts cursor key to the sort key (follow-up to #223)#230
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 DESCbut paginated withWHERE receipt_id < cursor.created_at(DB commit time) andreceipt_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 DESCalone, matching the cursor column (same fix as #223). One-line query change + comment.Test
tests/integration/test_admin_receipts_pagination.pyseeds receipts whosecreated_atandreceipt_idorderings maximally disagree, walks every page via the real/admin/receiptsroute, and asserts each receipt appears exactly once. Verified locally: passes with the fix, fails without it.