From b31a1cd01b5f689808c40688b78c3935fb427692 Mon Sep 17 00:00:00 2001 From: Gustav Bylund Date: Thu, 21 Mar 2024 13:49:01 +0100 Subject: [PATCH] fix(dependencies): only set default dependency_cache if it is None This solves a bug where an empty dictionary would be reassigned. --- 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 e2866b488..8a54d1ee7 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -587,7 +587,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) @@ -624,7 +625,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