-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.5.1
pydantic compiled: True
install path: /Users/shane/repos/domain-model-specification/Python/.venv/lib/python3.7/site-packages/pydantic
python version: 3.7.7 (default, Jul 18 2020, 22:28:30) [Clang 11.0.3 (clang-1103.0.32.62)]
platform: Darwin-19.6.0-x86_64-i386-64bit
optional deps. installed: ['typing-extensions']
Minimal Example
I'd like to enforce a condition on a whole model during arbitrary changes in its state:
from pydantic import BaseModel, root_validator
class Example(BaseModel):
current_value: float
max_value: float
class Config:
validate_assignment = True
@root_validator
def current_lessequal_max(cls, values):
current_value = values.get("current_value")
max_value = values.get("max_value")
assert abs(current_value) <= max_value, f"current_value cannot be greater than max_value"
return valuesBased on my reading of the docs I'd expect this to fail validation if I set current_value above max_value, or set max_value below current_value, on an existing instance. Is that not the intended behavior?
Thanks for an excellent library!
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X