-
Notifications
You must be signed in to change notification settings - Fork 307
Closed
Labels
good first issueGood for newcomersGood for newcomers
Description
I am getting quite a few of these Expected 'int' but got 'float' - serialized value may not be as expected
warnings in the log files. Is there a way to callout the specific field name?
I looked at Rust's exception and error message, and I don't see any "add_variable_context" flag.
If not easily possible, would it be possible to add the field name that is triggering the warning to PydanticSerializationError please.
The object that is triggering the exception has large number of sub-objects and fields, so going through all the fields would be very time consuming.
# Internal imports
# External imports
from pydantic import BaseModel
from pydantic_core import PydanticSerializationError
# Own imports
class TestModelDump(BaseModel):
int_value: int | None = None
float_value: float | None = None
def test_mismatch():
valu = TestModelDump(int_value=1, float_value=1.0)
result = valu.model_dump_json()
print(result)
valu = TestModelDump(int_value=1.0, float_value=1.0)
result = valu.model_dump_json(warnings="error")
print(result)
valu = TestModelDump(int_value=1.0, float_value=1)
valu.int_value = 1.0
valu.float_value = 1
try:
result = valu.model_dump_json(warnings="error")
except PydanticSerializationError as e:
print(e)
else:
print(result)
davidhewitt
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers