IN () Means Nothing — JavaScript Bug Hunt
Inspired by the empty-list crash that has paged every team with a query builder: WHERE id IN () is a syntax error in real databases.
- Language: JavaScript
- Layer: Database
- Difficulty: Easy
- Concepts: SQL, Edge Cases
- Modelled on: Query builders
- Visible tests: a normal batch selects its rows; an empty batch matches nothing without crashing
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-IN-EMPTY
- Reported by: batch jobs
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- an empty batch matches nothing without crashing — SyntaxError: unexpected token ')'
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 empty-list crash that has paged every team with a query builder: WHERE id IN () is a syntax error in real databases. The empty case must compile to a query that matches nothing — deliberately.
The mock engine (locked) is as strict as Postgres.
Bug report
BUG-IN-EMPTY · Priority: High · Reported by: batch jobs
selectByIds(ids) -> { sql, params }:
- non-empty: "SELECT * FROM items WHERE id IN (?, ?, …)" with params
- empty: "SELECT * FROM items WHERE 1=0" (matches nothing, no params)
Observed: the nightly job passes an empty batch and the whole run dies on a SQL syntax error.
Logs
[job] SyntaxError: unexpected token ')' in: ... WHERE id IN ()The code as shipped
src/sql/selectByIds.js (editable)
// Builds the batched select.
exports.selectByIds = function (ids) {
var marks = ids.map(function () { return "?"; }).join(", ");
return { sql: "SELECT * FROM items WHERE id IN (" + marks + ")", params: ids };
};
Read-only context: src/sql/engine.js.
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 JavaScript bug hunts.