You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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