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
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 edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.