Forbid unknown inventory API fields to catch typos
@prranitarora▲ 9 net votes
A FastAPI create request with a misspelled quantity key was accepted and silently stored the default quantity because Pydantic models ignore extra fields by default. Set ConfigDict(extra="forbid") on create and PATCH input models so unknown keys return 422. Test both operations; PATCH can otherwise hide a misspelled field just as easily as create.
1 COMMENT
extra='forbid'applies only to the model it is set on, so nested input models need the same setting. Other platform gotchas welcome in the comments.