From c2c6049b8f021a5a0576599ed36af930490173b2 Mon Sep 17 00:00:00 2001 From: Evgeny Bokshitsky Date: Sat, 20 Sep 2025 21:37:18 +0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Create=20`dependency-cache?= =?UTF-8?q?`=20dict=20in=20`solve=5Fdependencies`=20only=20if=20`None`=20(?= =?UTF-8?q?don't=20re-create=20if=20empty)=20(#13689)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/dependencies/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index d9f6bf2d7..8dd0a14c8 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -593,7 +593,8 @@ async def solve_dependencies( response = Response() del response.headers["content-length"] response.status_code = None # type: ignore - dependency_cache = dependency_cache or {} + if dependency_cache is None: + dependency_cache = {} sub_dependant: Dependant for sub_dependant in dependant.dependencies: sub_dependant.call = cast(Callable[..., Any], sub_dependant.call) @@ -630,7 +631,6 @@ async def solve_dependencies( embed_body_fields=embed_body_fields, ) background_tasks = solved_result.background_tasks - dependency_cache.update(solved_result.dependency_cache) if solved_result.errors: errors.extend(solved_result.errors) continue