resolved RESOLVED UNSUBMITTED PASS · None tool calls · 0 s · fastapi/fastapi
⬆️ Upgrade Starlette supported version range to >=0.40.0,<0.49.0 Starlette 0.48.0 introduced `HTTP_422_UNPROCESSABLE_CONTENT` as a new name for `HTTP_422_UNPROCESSABLE_ENTITY` and deprecated the old name due to RFC 9110; see https://github.com/Kludex/starlette/pull/2939. I updated all instances ~to the new name and increased the lower bound on the Starlette version~ to use the literal integer or string value `422`/`"422"` instead of either `HTTP_422_UNPROCESSABLE_CONTENT` or `HTTP_422_UNPROCESSABLE_ENTITY`, which makes FastAPI compatible with Starlette >=0.48 without deprecation warnings while preserving backwards compatibility with Starlette<0.48. @Kludex, FYI.
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- a/docs_src/handling_errors/tutorial005.py
+++ b/docs_src/handling_errors/tutorial005.py
@@ -1,4 +1,4 @@
-from fastapi import FastAPI, Request, status
+from fastapi import FastAPI, Request
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
@@ -10,7 +10,7 @@
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
return JSONResponse(
- status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+ status_code=422,
content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}),
)
--- a/fastapi/exception_handlers.py
+++ b/fastapi/exception_handlers.py
@@ -5,7 +5,7 @@
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
-from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY, WS_1008_POLICY_VIOLATION
+from starlette.status import WS_1008_POLICY_VIOLATION
async def http_exception_handler(request: Request, exc: HTTPException) -> Response:
@@ -21,7 +21,7 @@ async def request_validation_exception_handler(
request: Request, exc: RequestValidationError
) -> JSONResponse:
return JSONResponse(
- status_code=HTTP_422_UNPROCESSABLE_ENTITY,
+ status_code=422,
content={"detail": jsonable_encoder(exc.errors())},
)
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -35,7 +35,6 @@
from pydantic import BaseModel
from starlette.responses import JSONResponse
from starlette.routing import BaseRoute
-from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
from typing_extensions import Literal
validation_error_definition = {
@@ -416,7 +415,7 @@ def get_openapi_path(
)
deep_dict_update(openapi_response, process_response)
openapi_response["description"] = description
- http422 = str(HTTP_422_UNPROCESSABLE_ENTITY)
+ http422 = "422"
all_route_params = get_flat_params(route.dependant)
if (all_route_params or route.body_field) and not any(
status in operation["responses"]... [100%]
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.47.3-py3-none-any/starlette/testclient.py:51
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.47.3-py3-none-any/starlette/testclient.py:51: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
_PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
3 passed, 1 warning in 0.93s