Browse Source

️ Restore application usage of middleware for AsyncExitStack for dependencies with yield

pull/14099/head
Sebastián Ramírez 3 weeks ago
parent
commit
09dea83172
  1. 8
      fastapi/applications.py

8
fastapi/applications.py

@ -42,7 +42,7 @@ from starlette.middleware.exceptions import ExceptionMiddleware
from starlette.requests import Request from starlette.requests import Request
from starlette.responses import HTMLResponse, JSONResponse, Response from starlette.responses import HTMLResponse, JSONResponse, Response
from starlette.routing import BaseRoute from starlette.routing import BaseRoute
from starlette.types import ASGIApp, Lifespan, Receive, Scope, Send from starlette.types import ASGIApp, ExceptionHandler, Lifespan, Receive, Scope, Send
from typing_extensions import Annotated, Doc, deprecated from typing_extensions import Annotated, Doc, deprecated
AppType = TypeVar("AppType", bound="FastAPI") AppType = TypeVar("AppType", bound="FastAPI")
@ -971,7 +971,7 @@ class FastAPI(Starlette):
# inside of ExceptionMiddleware, inside of custom user middlewares # inside of ExceptionMiddleware, inside of custom user middlewares
debug = self.debug debug = self.debug
error_handler = None error_handler = None
exception_handlers = {} exception_handlers: dict[Any, ExceptionHandler] = {}
for key, value in self.exception_handlers.items(): for key, value in self.exception_handlers.items():
if key in (500, Exception): if key in (500, Exception):
@ -1011,8 +1011,8 @@ class FastAPI(Starlette):
) )
app = self.router app = self.router
for cls, options in reversed(middleware): for cls, args, kwargs in reversed(middleware):
app = cls(app=app, **options) app = cls(app, *args, **kwargs)
return app return app
def openapi(self) -> Dict[str, Any]: def openapi(self) -> Dict[str, Any]:

Loading…
Cancel
Save