We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
enum.Enum
We are using json_encoders={enum.Enum: lambda val: val.name} in pydantic V1. In V2, this setting seems to be ignored when migrating to V2.
json_encoders={enum.Enum: lambda val: val.name}
import enum import pydantic from pydantic import ConfigDict class MyEnum(enum.Enum): A = 'a' B = 'b' class A(pydantic.BaseModel): a: MyEnum model_config = ConfigDict(json_encoders={enum.Enum: lambda val: val.name}) print(A(a = MyEnum.A).model_dump_json()) # {"a":"a"}, expected {"a":"A"}
pydantic version: 2.1.1 pydantic-core version: 2.4.0 pydantic-core build: profile=release pgo=true mimalloc=true install path: .../lib/python3.10/site-packages/pydantic python version: 3.10.2 (main, Mar 3 2022, 12:03:29) [GCC 9.3.0] platform: Linux-5.14.0-1054-oem-x86_64-with-glibc2.35 optional deps. installed: ['typing-extensions']
Selected Assignee: @samuelcolvin
The text was updated successfully, but these errors were encountered:
@adriangb please can you have a look at this since you worked on json_encoders.
json_encoders
Sorry, something went wrong.
It's likely a bug stemming form the complexity in GenerateSchema. I think we can fix it, but it may not be trivial.
GenerateSchema
adriangb
Successfully merging a pull request may close this issue.
Initial Checks
Description
We are using
json_encoders={enum.Enum: lambda val: val.name}
in pydantic V1. In V2, this setting seems to be ignored when migrating to V2.Example Code
Python, Pydantic & OS Version
Selected Assignee: @samuelcolvin
The text was updated successfully, but these errors were encountered: