8000 🐛 Improve `jsonable_encoder` for other types of iterables by Lob26 · Pull Request #13803 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content

🐛 Improve jsonable_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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Lob26
Copy link
@Lob26 Lob26 commented Jun 18, 2025

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 from collections.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.

@Lob26 Lob26 changed the title Improve jsonable_encoder for other types of iterables feature: Improve jsonable_encoder for other types of iterables Jun 18, 2025
@Lob26 Lob26 marked this pull request as draft June 18, 2025 22:06
@Lob26 Lob26 force-pushed the jsonable_encoder branch from 4d7431e to 5961a8c Compare June 19, 2025 19:54
@svlandeg svlandeg added the bug Something isn't working label Jun 23, 2025
@svlandeg svlandeg changed the title feature: Improve jsonable_encoder for other types of iterables 🐛 Improve jsonable_encoder for other types of iterables Jun 23, 2025
from pydantic.networks import AnyUrl, NameEmail
from pydantic.types import SecretBytes, SecretStr
from pydantic_extra_types.color import Color
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for Coordinate type

@rhealakhotia
Copy link

Hi @Lob26, I’m new to open source but would love to help with this.
Could you clarify:

  • Which edge cases still need testing?
  • How to reproduce the SQLAlchemy row issue locally?

I’ll try to write a test case and debug the CI failures. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0