Browse Source

⬆️ Upgrade Starlette supported version range to >=0.40.0,<0.49.0 (#14077)

Co-authored-by: svlandeg <svlandeg@github.com>
pull/14075/head
Ben Beasley 20 hours ago
committed by GitHub
parent
commit
7563579dc8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      docs_src/handling_errors/tutorial005.py
  2. 4
      fastapi/exception_handlers.py
  3. 3
      fastapi/openapi/utils.py
  4. 2
      pyproject.toml
  5. 2
      tests/test_enforce_once_required_parameter.py

4
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.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
@ -10,7 +10,7 @@ app = FastAPI()
@app.exception_handler(RequestValidationError) @app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError): async def validation_exception_handler(request: Request, exc: RequestValidationError):
return JSONResponse( return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, status_code=422,
content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}), content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}),
) )

4
fastapi/exception_handlers.py

@ -5,7 +5,7 @@ from fastapi.websockets import WebSocket
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.requests import Request from starlette.requests import Request
from starlette.responses import JSONResponse, Response 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: async def http_exception_handler(request: Request, exc: HTTPException) -> Response:
@ -21,7 +21,7 @@ async def request_validation_exception_handler(
request: Request, exc: RequestValidationError request: Request, exc: RequestValidationError
) -> JSONResponse: ) -> JSONResponse:
return JSONResponse( return JSONResponse(
status_code=HTTP_422_UNPROCESSABLE_ENTITY, status_code=422,
content={"detail": jsonable_encoder(exc.errors())}, content={"detail": jsonable_encoder(exc.errors())},
) )

3
fastapi/openapi/utils.py

@ -35,7 +35,6 @@ from fastapi.utils import (
from pydantic import BaseModel from pydantic import BaseModel
from starlette.responses import JSONResponse from starlette.responses import JSONResponse
from starlette.routing import BaseRoute from starlette.routing import BaseRoute
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
from typing_extensions import Literal from typing_extensions import Literal
validation_error_definition = { validation_error_definition = {
@ -416,7 +415,7 @@ def get_openapi_path(
) )
deep_dict_update(openapi_response, process_response) deep_dict_update(openapi_response, process_response)
openapi_response["description"] = description openapi_response["description"] = description
http422 = str(HTTP_422_UNPROCESSABLE_ENTITY) http422 = "422"
all_route_params = get_flat_params(route.dependant) all_route_params = get_flat_params(route.dependant)
if (all_route_params or route.body_field) and not any( if (all_route_params or route.body_field) and not any(
status in operation["responses"] status in operation["responses"]

2
pyproject.toml

@ -43,7 +43,7 @@ classifiers = [
"Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP",
] ]
dependencies = [ dependencies = [
"starlette>=0.40.0,<0.48.0", "starlette>=0.40.0,<0.49.0",
"pydantic>=1.7.4,!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0", "pydantic>=1.7.4,!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0",
"typing-extensions>=4.8.0", "typing-extensions>=4.8.0",
] ]

2
tests/test_enforce_once_required_parameter.py

@ -102,7 +102,7 @@ def test_schema():
def test_get_invalid(): def test_get_invalid():
response = client.get("/foo") response = client.get("/foo")
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == 422
def test_get_valid(): def test_get_valid():

Loading…
Cancel
Save