-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
jsonable_encoder does not take the Config into account for Enums #196
Comments
Thanks for the report. I'll check it. |
I'm delaying this until pydantic/pydantic#520 is resolved. It will change how responses are encoded from Pydantic models in a much cleaner way. And it will solve several issues at the same time (most probably including this). |
Pydantic has a recent/new ORM mode. I just finished a deep integration of it into FastAPI. It is released in version Now, if you use a If you use ORM object (SQLAlchemy, Peewee, etc) you should use Pydantic's Also, in case I'm misunderstanding the question, specific to the configs set in Pydantic models, I'm pretty sure the |
I assume this was solved in recent versions, so I'll close this issue. But feel free to add more comments or create new issues. |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
When calling
jsonable_encoder
on a pydantic object that makes use of anEnum
for a field, the JSON response contains theEnum.field.value
, whereas the default behavior should be to useEnum.field.name
(as per theConfig.use_enum_values
which isFalse
by default)in the code, file encoders.py, around line 26:
To Reproduce
Steps to reproduce the behavior:
jsonable_encoder
on an instance{'type': 'CountValue'}
instead of{'type': 'count'}
Expected behavior
The expected behavior should be to check the value of the
Config.use_enum_values
and return the name or the value appropriatelyEnvironment:
The text was updated successfully, but these errors were encountered: