Browsing without an account — progress is saved in this browser only.Sign in to save it
Debugging validation models: absent is not the same as null
Reading20 min
Pydantic models are the boundary between the outside world and your data. A bug here rarely raises: it quietly writes the wrong thing. The skill this section trains is asking, for every field, what the model does when the client sends it, omits it, or sends null.
Three states, two representations
A PATCH body can contain a value, an explicit null (clear this field) or nothing at all (leave it alone). A model field with a default of None collapses the last two. Pydantic remembers which fields were actually provided: model_dump(exclude_unset=True) returns exactly those. model_dump() returns everything, defaults included, so applying it overwrites the fields the client never mentioned. Reproduce it by sending a single field and reading the whole resource back.
Sign in to try this knowledge check.