Distinguish missing from nullable
A nullable field is allowed to contain None. That does not automatically give the field a default. In Pydantic 2, an annotation such as str | None is still required unless a default is supplied.
This distinction matters for partial forms and API updates. Missing means the caller did not send a value; an explicit null may mean clear an existing value. Use model_fields_set when that distinction must survive validation, and avoid replacing all missing fields with None before you validate them.
from pydantic import BaseModel
class Note(BaseModel):
text: str | None = None
print(Note().model_fields_set)
print(Note(text=None).model_fields_set)Your task
Define Patch with nullable title defaulting to None. patch_data(raw) must return only fields explicitly supplied, using exclude_unset=True. Preserve an explicit title=None and ignore unknown fields.
The explanation opens here once every check passes.