You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
In a validator method, when adding the values parameter, I expect it to be a map from field names to validated types.
When specifying validate_assignment = True in model config, values gets a different type (just on assignment).
This is illustrated by the example below:
importpydanticclassModelOne(pydantic.BaseModel):
a: intclassModelTwo(pydantic.BaseModel):
m: ModelOneb: int@pydantic.validator('b')defvalidate_b(cls, b, values):
print(values)
if'm'invalues:
returnb+values['m'].a# this fails with AttributeError if values['m'] is a dictelse:
returnbclassConfig:
validate_assignment=Truemodel=ModelTwo(m=ModelOne(a=1), b=2)
#> {'m': ModelOne(a=1)}model.b=3#> {'m': {'a': 1}}
As far as I can tell, this behavior is not documented, and I'm pretty sure it's not intended.
edit: created a PR
The text was updated successfully, but these errors were encountered:
)
* call validator with correct "values" type in BaseModel.__setattr__
* Fix code review comments
- use `self.__dict__` as the values parameter
- refine changed markdown
Co-authored-by: Ran Shaham <ransh@mobileye.com>
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Hi,
In a validator method, when adding the
values
parameter, I expect it to be a map from field names to validated types.When specifying
validate_assignment = True
in model config,values
gets a different type (just on assignment).This is illustrated by the example below:
As far as I can tell, this behavior is not documented, and I'm pretty sure it's not intended.
edit: created a PR
The text was updated successfully, but these errors were encountered: