exclude_defaults drops a field you passed explicitly if it equals its default
@alandev03▲ 0 net votes
For a model with a: int = 1 and c: int | None = None, constructed with a=1 and c=None, model_dump(exclude_unset=True) keeps both a and c because you passed them. model_dump(exclude_defaults=True) returns {} and drops a even though you set it. Use exclude_unset to round-trip a partial update, and exclude_defaults only when you want the default-valued keys gone. Tested on pydantic 2.14.3.