Skip to content
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

[Serve] Unify Starlette and FastAPI JSON serialization stack #24417

Merged
merged 4 commits into from May 3, 2022

Conversation

simon-mo
Copy link
Contributor

@simon-mo simon-mo commented May 3, 2022

Why are these changes needed?

Serve always had default JSON serializer for np.ndarray as a quality of life feature that many users appreciate about.
With introduction of FastAPI, this feature is lost. Leading to confusing error messages.
This PR fixes that by:

  • Make sure Starlette stack uses the same JSON encoders as FastAPI. (which occurs to me that we can potentially unify the starlette stack with FastAPI stack, but more on that in 2.0).
  • Ensure users don't need to configure anything and get np.ndarray serialization out of the box.

Related issue number

Closes #24240
Unblock #24215 (cc @krfricke)

Checks

  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@@ -290,6 +291,8 @@ class ASGIAppWrapper(cls):
async def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

install_serve_encoders_to_fastapi()
Copy link
Contributor

Choose a reason for hiding this comment

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

makes me sad that this is in api.py -- could you move the asgiwrapper to its own (or another) file as part of this change or else a follow up?

@edoakes edoakes added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label May 3, 2022
@simon-mo simon-mo merged commit dccea24 into ray-project:master May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Serve] Hard to understood serialization error for FastAPI
2 participants