A client handed me a paginated API client with 39 tests, all green. One test asserted that page two reports has_more = False. It was not a specification. It was a photograph of a bug.
The shape is ordinary. The server returns rows older than the cursor, and it includes the cursor row itself so the caller can confirm where it is. The client over-fetches by one to decide has_more:
rows = server_page(cursor, limit + 1) # one extra row, for has_more if cursor is not None: rows = [r for r in rows if r["lt"] != cursor] # drop the row already shown has_more = len(rows) > limit # never true when paging return rows[:limit], has_more Page one looks right. There is no cursor row to drop, the extra row survives, and has_more can be true. From page two on you fetch limit + 1 rows, throw the first away, and hold at most limit. len(rows) > limit is false by construction. Every paged request says "that is the end", and the caller stops with rows still on the server.
I built a ten row server behind this to check, page size three. The file is 60 lines, no dependencies: demo.py. Same test, two builds:
$ python3 demo.py buggy: page1 lts=[1, 2, 3] has_more=True page2 lts=[4, 5, 6] has_more=False (4 rows remain) drained: 6 of 10 rows in 2 pages, unique=6, last_has_more=False $ python3 demo.py --fixed fixed: page1 lts=[1, 2, 3] has_more=True page2 lts=[4, 5, 6] has_more=True (4 rows remain) drained: 10 of 10 rows in 4 pages, unique=10, last_has_more=False The suite passes in both runs. It checks the cursor row is not repeated, and the cursor row is not repeated. What it cannot see is the four rows nobody asked for, because after has_more = False nobody asks.
The fix is a budget: limit + 2 when a cursor is present, so the drop leaves limit rows plus one probe. If the server caps your limit below that, make one two row request from the cursor before answering, or you are guessing.
Two rules I keep from this:
-
has_moremust be computed from rows fetched to answer it, not from rows you kept. - A test named after the symptom you noticed is not a test of the behaviour you implemented.
I found this on someone else's file, wrote the failing test first, and watched it go red on their green suite. Their tests were not wrong. They were asked the wrong question.
If you have a command that fails and the error it prints, that is the job I take: reproduce it from the published source, patch the cause, prove both ends in one environment. Example receipt: video-cli 1.3.3 is dead on a plain install. Repair listing: Failing command: reproduced, patched, proven.


