Review null and empty input paths
Code written against the happy record in the developer's head crashes on the real database, where that column is NULL and that relation is an empty list.
Procedure
- List new dereferences and iterations in the diff:
gh pr diff 482 | grep -nE '^\+.*(\.[a-z_]+\.|for .* in |\.map\(|\.forEach\(|\[0\]|\.get\(\))'. - For every field touched, ask whether the source can be null: nullable DB columns, optional JSON, map lookups that miss,
find/querySelectorthat can return nothing. - Trace the three empties separately — they fail differently:
null/None/undefined— dereference throws,""— passes a!= nullcheck but fails truthiness and length,[]/{}—.first()or[0]is an index error.
- Check optional chaining and its silent half:
a?.b.cstill throws ifbis undefined; you needa?.b?.c. An??default does not apply when the value is""or0. - Verify the empty case has defined behaviour: return an empty result, skip, or raise a typed error — not an unhandled crash.
- In SQL, confirm
NOT INagainst a subquery that can yieldNULLis not silently returning zero rows. - Add a test per empty kind, with the field literally set to
None,"", and[].
Pitfalls
- Guarding with
if x:so a legitimate0or""is treated as missing. - Optional chaining on the outer object but not the inner property, moving the crash one level down.
- A default of
[]created in an argument list (def f(items=[])) shared across calls and mutated. - An empty collection passed to a
min/max/.reducethat raises instead of returning a sentinel.
Verification
pytest tests/ -q -k "none or empty or null"
# Also exercise the live type: assert the field is Optional in the schema.
gh pr diff 482 | grep -nE '^\+.*\?\?|is None|!= null|Optional'
Report each new field and the empty inputs you traced, or state that null, empty-string, and empty-collection inputs are each covered by a test.
Worked example
A change adds return user.profile.avatar.url. profile is a nullable one-to-one, so a user without one raises AttributeError. The fix:
return user.profile.avatar.url if user.profile else DEFAULT_AVATAR
The tests set profile=None, then avatar="", then url="", and assert the default avatar is returned for each — three distinct empties, three assertions.