From 09dea831724a9759395e7ed6a5bfd5c04825f085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 3 Sep 2025 19:13:10 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Restore=20application=20us?= =?UTF-8?q?age=20of=20middleware=20for=20AsyncExitStack=20for=20dependenci?= =?UTF-8?q?es=20with=20yield?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/applications.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index c5a8f1228..3bf30f883 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -42,7 +42,7 @@ from starlette.middleware.exceptions import ExceptionMiddleware from starlette.requests import Request from starlette.responses import HTMLResponse, JSONResponse, Response 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 AppType = TypeVar("AppType", bound="FastAPI") @@ -971,7 +971,7 @@ class FastAPI(Starlette): # inside of ExceptionMiddleware, inside of custom user middlewares debug = self.debug error_handler = None - exception_handlers = {} + exception_handlers: dict[Any, ExceptionHandler] = {} for key, value in self.exception_handlers.items(): if key in (500, Exception): @@ -1011,8 +1011,8 @@ class FastAPI(Starlette): ) app = self.router - for cls, options in reversed(middleware): - app = cls(app=app, **options) + for cls, args, kwargs in reversed(middleware): + app = cls(app, *args, **kwargs) return app def openapi(self) -> Dict[str, Any]: