Skip to content
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

Improve error message when enum validation fails #175

Open
drewm1980 opened this issue Mar 4, 2022 · 0 comments
Open

Improve error message when enum validation fails #175

drewm1980 opened this issue Mar 4, 2022 · 0 comments

Comments

@drewm1980
Copy link

drewm1980 commented Mar 4, 2022

I made the following usage mistake:

I used another json library (orjson) to convert to and from JSON, thinking I could get away with only using marshmallow for deserialization.

orjson serializes Enums by value, but marshmallow serializes Enums by key, resulting in an error:

  File "/home/awagner/miniconda3/envs/luigi_py36/lib/python3.6/site-packages/marshmallow/schema.py", line 904, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'model_size': ['Invalid enum member MyEnumValue']}

The solution was to use marshmallow for both serialization and deserialization.

If this is a common enough mistake, perhaps the error message could be improved, especially since you can detect if the value found matches one of the expected enum values. (in my case the Enum was string valued)

Otherwise, this ticket at least gives something for people to hit while searching.

Thanks for the useful library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant