The Cursor at the End of Time — Python Bug Hunt
Inspired by the API-pagination crashes that greet every client's FIRST request: the opaque cursor is decoded unconditionally — and the first page has no…
- Language: Python
- Layer: Database
- Difficulty: Medium
- Concepts: Pagination, Parsing
- Modelled on: REST APIs
- Visible tests: the first page has no cursor; cursors round-trip; junk cursors raise instead of restarting
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-PAGE1
- Reported by: API consumers
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- the first page has no cursor — 'NoneType' object has no attribute 'split'
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the data through the query or the repository code; compare the rows it returns with the rows the report expects.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the API-pagination crashes that greet every client's FIRST request: the opaque cursor is decoded unconditionally — and the first page has no cursor at all. int("") says hello.
cursor.py encodes/decodes offset cursors of the form "off:<n>".
Bug report
BUG-PAGE1 · Priority: High · Reported by: API consumers
- decode(cursor): None or "" -> offset 0; "off:<n>" -> n; anything else -> raise ValueError
- encode(offset) -> "off:<n>"; round-trips exactly
Observed: the very first request (no cursor) throws, and junk cursors return offset 0 silently, restarting angry clients from page one.
Logs
[api] GET /items -> 500 ValueError: invalid literal for int()The code as shipped
src/api/cursor.py (editable)
# Opaque pagination cursors: "off:<n>".
def encode(offset):
return "off:" + str(offset)
def decode(cursor):
return int(cursor.split(":")[1])
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.