Skip to content

Commit

Permalink
Don't warn on missing fields if exclude_* are used (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb authored Jul 3, 2023
1 parent 2a943a3 commit d285975
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/serializers/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ impl TypeSerializer for GeneralFieldsSerializer {
}
}
}
if td_extra.check.enabled() && self.required_fields != used_req_fields {
if td_extra.check.enabled()
// If any of these are true we can't count fields
&& !(extra.exclude_defaults || extra.exclude_unset || extra.exclude_none)
// Check for missing fields, we can't have extra fields here
&& self.required_fields > used_req_fields
{
return Err(PydanticSerializationUnexpectedValue::new_err(None));
}
// this is used to include `__pydantic_extra__` in serialization on models
Expand Down

0 comments on commit d285975

Please sign in to comment.