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
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
This code sample, which contains a minor typo converting an intended default for an integer field into a tuple:
from pydantic import BaseModel, ConfigDict
class MyBaseModel(BaseModel):
model_config = ConfigDict(validate_default=True)
class Command(MyBaseModel):
chan: int = 0,
val: int = 0
validated = Command(val = 'f')
Produces this output:
Traceback (most recent call last):
File "/home/pi/blinka/BugTest.py", line 11, in <module>
validated = Command(val = 'f')
^^^^^^^^^^^^^^^^^^
File "/home/pi/blinka/lib/python3.11/site-packages/pydantic/main.py", line 176, in __init__
self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Command
chan
Input should be a valid integer [type=int_type, input_value=(0,), input_type=tuple]
For further information visit https://errors.pydantic.dev/2.7/v/int_type
val
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='f', input_type=str]
For further information visit https://errors.pydantic.dev/2.7/v/int_parsing
This is hard to understand because the identifier 'chan' does not appear anywhere in the highlighted traceback (line 11). I suggest that the field identifier should be presented more verbosely, both in the case where it is taken from the constructor argument list and in the case where it is defaulted. Say, something like:
Field: chan (default value from Command schema)
Input should be a valid integer [type=int_type, input_value=(0,), input_type=tuple]
For further information visit https://errors.pydantic.dev/2.7/v/int_type
Field: val
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='f', input_type=str]
For further information visit https://errors.pydantic.dev/2.7/v/int_parsing
Thanks for the feature request. I think this is a reasonble feature request - effectively to be more clear about where the input value is coming from in the error message. That being said, I do find the error message to be quite clear in general, so I wouldn't say this is high on our list of priorities.
Initial Checks
Description
This code sample, which contains a minor typo converting an intended default for an integer field into a tuple:
Produces this output:
This is hard to understand because the identifier 'chan' does not appear anywhere in the highlighted traceback (line 11). I suggest that the field identifier should be presented more verbosely, both in the case where it is taken from the constructor argument list and in the case where it is defaulted. Say, something like:
Suggestion comes out of this thread:
#9389
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: