-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Description
Context:
In [24]: class C(BaseModel):
...: foo: int
...:
In [25]: C(foo="42")
Out[25]: C(foo=42)
In [26]: C.model_validate({"foo": "42"})
Out[26]: C(foo=42)
In [27]: C.model_validate({"foo": "42"}, strict=True)
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[27], line 1
----> 1 C.model_validate({"foo": "42"}, strict=True)
File ~/.cache/uv/archive-v0/j9AUHBx4OV-OhSDXYcYzU/lib/python3.8/site-packages/pydantic/main.py:627, in BaseModel.model_validate(cls, obj, strict, from_attributes, context)
625 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
626 __tracebackhide__ = True
--> 627 return cls.__pydantic_validator__.validate_python(
628 obj, strict=strict, from_attributes=from_attributes, context=context
629 )
ValidationError: 1 validation error for C
foo
Input should be a valid integer [type=int_type, input_value='42', input_type=str]
For further information visit https://errors.pydantic.dev/2.10/v/int_typeToday, we use Pydantic's "magic" .model_dump in ops.Relation.save() but we instantiate the type directly in ops.Relation.load().
If we used Pydantic's "magic" .model_validate, we could pass in strict=True and avoid type coersion.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels