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
fromtypingimportSetfrompydanticimportvalidate_argumentsmy_set= {"assaf"}
print(f"{id(my_set)=}")
defa(b: Set[str]):
print(f"first {id(b)=}")
a(my_set)
@validate_argumentsdefa(b: Set[str]):
print(f"second {id(b)=}")
a(my_set)
@validate_arguments(config=dict(copy_on_model_validation=False))defa(b: Set[str]):
print(f"third {id(b)=}")
a(my_set)
""" ... ... Model Configcopy_on_model_validationwhether or not inherited models used as fields should be reconstructed (copied) on validation instead of being kept untouched (default: True)"""
output:
id(my_set)=139856697296704
first id(b)=139856697296704
second id(b)=139856688179456
third id(b)=139856688107584
I think with the decorator validate_arguments it's need to be same as the original python behavior, but if it doesn't the config should support it.
The text was updated successfully, but these errors were encountered:
@assaf-orca When we validate a set, we always re-create it - same as we do with pydantic models, so the id changes
it's really a fundamental limitation/feature of Pydantic
Why was this bug closed?
The bug is still present in the code.
"When we validate a set, we always re-create it" contradicts copy_on_model_validation being set to 'none'.
The code/validator should fault at when it's unable to honor the copy_on_model_validation of 'none'. (E.x.: It's given an iterator - or - you would need to convert the items in the sequence to make the contract work) instead of silently breaking the contract/requirement.
Without that type of enforcement, you'll just have people shooting themselves in the foot left and right because changes to the collection or object are not being propagated to the caller.
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:output:
I think with the decorator validate_arguments it's need to be same as the original python behavior, but if it doesn't the config should support it.
The text was updated successfully, but these errors were encountered: