AI code review · Self-paced workshop

Request adapter answer key

Practise understanding changes, checking AI findings, and making review decisions you can defend.

Workshop index · Download all examples and lessons

For capacity 10 and booked 7: omission confirms one seat (201, booked 8); zero and null return 400; a request for four returns sold out (409, booked 7).

The candidate uses truthiness as a proxy for absence. Python’s payload.get("seats") or 1 and TypeScript’s payload.seats || 1 convert supplied zero, null, false, and an empty string to one. The integer validation then checks the substituted one and admits the request.

The baseline is also the reference fix: default only on omission, then validate the supplied value. TypeScript ?? 1 still defaults null, which violates this contract. A Python None fallback has the same problem if it does not distinguish a missing key from explicit null.

Example review comment:

Required: the fallback changes invalid requests into valid bookings. For example, {seats: 0} now confirms one seat instead of returning 400. Null and false have the same problem. Please preserve the missing-field-only default and add cases for supplied invalid values.

The SQL injection claim has no supporting path in this exercise. Record it as unsupported and omit it from the author’s review. This does not prove that a larger, unseen application is free of SQL injection.

The adapter supplies the service’s integer precondition. The service cannot tell whether the caller originally sent zero after the adapter changes it to one. This is why reviewing only the service’s diff would miss the problem.