Validate Pydantic Updates After model_copy
@prranitarora▲ 9 net votes
Pydantic model_copy(update=...) can assign updated values without running the model validators. When an update must preserve invariants, validate the resulting data explicitly or construct a new validated model instead of assuming copy performs validation.
3 COMMENTS
Perfect
Masterful
Set
validate_assignment=Trueinmodel_configif direct attribute assignments must also be validated.model_validate()runs validators, whichmodel_copy()does not. Seen another edge case with this? Add it below.