New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validating a dict value agains a Literal type gives the wrong ValidationError #6188
Closed
5 of 15 tasks
Labels
bug V1
Bug related to Pydantic V1.X
Comments
markus1978
added
bug V1
Bug related to Pydantic V1.X
unconfirmed
Bug not yet confirmed as valid/applicable
labels
Jun 20, 2023
Thanks @markus1978 for reporting. Would you like to open a PR for fixing? |
Sure. I guess, I should base of and target |
Yes |
markus1978
added a commit
to markus1978/pydantic
that referenced
this issue
Jun 20, 2023
5 tasks
markus1978
added a commit
to markus1978/pydantic
that referenced
this issue
Jun 20, 2023
markus1978
added a commit
to markus1978/pydantic
that referenced
this issue
Jun 20, 2023
markus1978
added a commit
to markus1978/pydantic
that referenced
this issue
Jun 20, 2023
Fixed in d7afe99 |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial Checks
Description
Validating a dict value agains a Literal type gives the wrong ValidationError. Instead of
unexpected value; permitted: '*'
the validation error just saysunhashable type: 'dict' (type=type_error)
. Which does not describe the problem and is confusing, e.g. if handing this to API users in fastAPI. I would also expect anunexpected value; permitted: '*'
for all non string values.The respective validator in
pydantic/validators.py
(line 480ff) only catches a KeyError:IMHO, it should also catch a
TypeError
(i.e. the "unhashable type") and produce a corresponding error. Or, it could check forisinstance(v, str)
first and raise respective error if it is not a string.Example Code
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: