[BUG] Custom encoders leak in jsonable_encoder #11538
ashleymajar
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I think I found a bug in FastAPI's encoders.py:
In the implementation of jsonable_encoder, if a Pydantic BaseModel with json_encoders is serialized, and custom_encoder is provided, the custom_encoder will leak into the json_encoders of the Pydnatic BaseModel.
It's kinda deprecated because it only happens with Pydantic 1, but still, a lot of people use it.
I patched it by copying the json_encoders and not updating it directly, a similar solution should work well in FastAPI too.
Operating System
Linux, Windows, macOS, Other
Operating System Details
It's not OS-related
FastAPI Version
0.103.2 but also in older ones
Pydantic Version
2.7.1
Python Version
3.12.3
Additional Context
It's more of a bug report than a question, but the issues instruct to post it here
Beta Was this translation helpful? Give feedback.
All reactions