Skip to content

Commit

Permalink
[Serve] Pin the fastapi & starlette version to avoid breaking proxy (r…
Browse files Browse the repository at this point in the history
…ay-project#42682)

Pin the fastapi version to 0.108.0. The latest version of fastapi is breaking with starlette. (issue)
Add starlette compact for supporting >= 0.35.0 version.

---------

Signed-off-by: Sihan Wang <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
  • Loading branch information
sihanwang41 and edoakes authored Jan 26, 2024
1 parent 726c55f commit 053085e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
16 changes: 13 additions & 3 deletions python/ray/serve/_private/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Type

import grpc
import starlette
import starlette.routing
import uvicorn
from packaging import version
from starlette.datastructures import MutableHeaders
from starlette.middleware import Middleware
from starlette.types import Receive
Expand Down Expand Up @@ -1211,9 +1213,17 @@ def __init__(
self.wrapped_http_proxy = self.http_proxy

for middleware in http_middlewares:
self.wrapped_http_proxy = middleware.cls(
self.wrapped_http_proxy, **middleware.options
)
if version.parse(starlette.__version__) <= version.parse("0.34.0"):
self.wrapped_http_proxy = middleware.cls(
self.wrapped_http_proxy, **middleware.options
)
else:
# Starlette >= 0.35.0
self.wrapped_http_proxy = middleware.cls(
self.wrapped_http_proxy,
*middleware.args,
**middleware.kwargs,
)

# Start running the HTTP server on the event loop.
# This task should be running forever. We track it in case of failure.
Expand Down
4 changes: 2 additions & 2 deletions python/requirements/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cloudpickle==2.2.0
# Keep in sync with `ci/build/upload_build_info.sh`
cryptography==38.0.1
cython==0.29.32
fastapi==0.104.0
fastapi==0.108.0
feather-format==0.4.1
# Keep compatible with Werkzeug
flask==2.1.3
Expand Down Expand Up @@ -93,7 +93,7 @@ importlib-metadata==4.10.0
# Some packages have downstream dependencies that we have to specify here to resolve conflicts.
# Feel free to add (or remove!) packages here liberally.
tensorboardX==2.6.0
starlette==0.27.0
starlette==0.29.0
h11==0.12.0
markdown-it-py==1.1.0
attrs==21.4.0
Expand Down
4 changes: 2 additions & 2 deletions python/requirements_compiled.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ fairscale==0.4.6
# via -r /ray/ci/../python/requirements/ml/tune-test-requirements.txt
farama-notifications==0.0.4
# via gymnasium
fastapi==0.104.0
fastapi==0.108.0
# via
# -r /ray/ci/../python/requirements.txt
# -r /ray/ci/../python/requirements/test-requirements.txt
Expand Down Expand Up @@ -2175,7 +2175,7 @@ sshpubkeys==3.3.1
# via moto
stack-data==0.6.3
# via ipython
starlette==0.27.0
starlette==0.29.0
# via
# -r /ray/ci/../python/requirements.txt
# -r /ray/ci/../python/requirements/test-requirements.txt
Expand Down
3 changes: 2 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def get_packages(self):
"uvicorn[standard]",
"requests",
"starlette",
"fastapi",
# Tracking issue: https://github.com/tiangolo/fastapi/discussions/10948
"fastapi <= 0.108.0",
"watchfiles",
],
"tune": ["pandas", "tensorboardX>=1.9", "requests", pyarrow_dep, "fsspec"],
Expand Down

0 comments on commit 053085e

Please sign in to comment.