Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.6k
🐛 Improvejsonable_encoder
for other types of iterables#13803
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
jsonable_encoder
for other types of iterablesfastapi/encoders.py Outdated
from pydantic.networks import AnyUrl, NameEmail | ||
from pydantic.types import SecretBytes, SecretStr | ||
from pydantic_extra_types.color import Color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This package supports pydantic 2.x only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same forCoordinate
type
rhealakhotia commentedJul 13, 2025
Hi@Lob26, I’m new to open source but would love to help with this.
I’ll try to write a test case and debug the CI failures. Thanks! |
What was changed
Updated the jsonable_encoder function to correctly handle any iterable type.
Reordered conditionals to ensure the iterable check occurs later, allowing appropriate handling to other type-specific branches (which previously caused failures).
Why this change is necessary
The previous implementation did not correctly serialize objects like
sqlalchemy.engine.Row
, which inherit fromcollections.abc.Sequence
but behave differently than standard lists or tuples. This led to unexpected failures or incorrect encoding.Testing
Manually tested the updated function against a wide variety of data structures
Behavior appears consistent and correct across all tested inputs.
Notes
While the function now gracefully handles many iterables, I'm still wary there may be edge cases I haven't considered. Further review and test cases are welcome.