Skip to content

Commit d285975

Browse files
authored
Don't warn on missing fields if exclude_* are used (#727)
1 parent 2a943a3 commit d285975

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/serializers/fields.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,12 @@ impl TypeSerializer for GeneralFieldsSerializer {
205205
}
206206
}
207207
}
208-
if td_extra.check.enabled() && self.required_fields != used_req_fields {
208+
if td_extra.check.enabled()
209+
// If any of these are true we can't count fields
210+
&& !(extra.exclude_defaults || extra.exclude_unset || extra.exclude_none)
211+
// Check for missing fields, we can't have extra fields here
212+
&& self.required_fields > used_req_fields
213+
{
209214
return Err(PydanticSerializationUnexpectedValue::new_err(None));
210215
}
211216
// this is used to include `__pydantic_extra__` in serialization on models

0 commit comments

Comments
 (0)