NULL Isn't Equal to NULL — Python Bug Hunt
Inspired by the SQL lesson everyone learns in production: WHERE col = NULL matches nothing, ever — three-valued logic demands IS NULL.
- Language: Python
- Layer: Database
- Difficulty: Medium
- Concepts: SQL, NULL Semantics
- Modelled on: SQL three-valued logic
- Visible tests: null filters use IS NULL; concrete values still match with equals
- Reward: 50 XP for a complete fix
Briefing
Inspired by the SQL lesson everyone learns in production: WHERE col = NULL matches nothing, ever — three-valued logic demands IS NULL. The report for "orders without a shipping date" has been returning zero rows for a month.
where_builder.py generates the clause; the locked engine follows real SQL semantics.
Bug report
BUG-3VL · Priority: High · Reported by: analytics
build_where(field, value):
- value is None -> {"clause": "<field> IS NULL", "params": []}
- otherwise -> {"clause": "<field> = ?", "params": [value]}
Observed: None becomes "= ?" with a NULL param — the engine (correctly) matches nothing, and ops thinks every order shipped.
Logs
[report] unshipped orders: 0 (warehouse says: definitely not zero)The code as shipped
src/sql/where_builder.py (editable)
# Builds a WHERE clause for a single field.
def build_where(field, value):
return {"clause": field + " = ?", "params": [value]}
Read-only context: src/sql/sqlengine.py.
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.