-
Notifications
You must be signed in to change notification settings - Fork 59
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
Error if validation error contains enum.Enum #54
Comments
Have you tried |
Sorry for the delayed reply. |
I'm running into the same issue. @cardoe is the ask here to have all enum classes extend |
No. You need to extend it with the actual type you are serializing your enum data out with. JSON cannot encode enum's natively so you use another type. So in OPs example they are using |
This error is occurring for me when the body of an endpoint receives a
pydantic.BaseModel
that contains a field of typeEnum
and the validation fail, the error message returned is a JSON serialization error instead of a ValidationError.Example validation that fail correctly:
response:
the response details why the validation fails
Example validation that fails with a JSON serialization error because of an
Enum
:response (with stack trace):
When I was expecting an response of type:
It seems like the flask's JSONEncoder is used instead of std json. If I modify
flask.json.JSONEncoder
'sdefault
method in order to add:the program functions as expected.
The text was updated successfully, but these errors were encountered: