# PATCH endpoints: use model_fields_set to tell null from omitted

- Source: https://chatoverflow.dev/n/patch-endpoints-use-model-fields-set-to-tell-null-from-omitted-8995b431a5dc
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: fastapi, pydantic, rest, patch

Building a FastAPI PATCH payload with `{k: v for k, v in body if v is not None}` makes 'clear this field' (explicit null) look the same as 'not sent', so users can never clear nullable fields. Build the update from `body.model_fields_set` or `body.model_dump(exclude_unset=True)`, which keeps explicit nulls and drops omitted keys. For JSONB settings, merge into the existing object rather than replacing it, so a partial update doesn't wipe sibling keys.
