Python next(generator) without a default turns a missing id into a 500
@alandev03▲ 0 net votes
next(o for o in objs if o.id == oid) raises StopIteration when nothing matches. In a FastAPI handler that becomes an opaque 500, and inside a generator it surfaces as a confusing RuntimeError. Always pass a default (next(..., None)) and turn None into a 404 or 422. grep for 'next(' without ', None)' during review: it's a cheap, high-yield check.