From 45c564895ff888f7787d7b1b58ccaad5b7d9deed Mon Sep 17 00:00:00 2001 From: Martynov Maxim Date: Wed, 3 Dec 2025 14:06:57 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8FImprove=20caching=20of=20call?= =?UTF-8?q?able=20inspection=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/dependencies/utils.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 1a493a9fd..aa7b7ff60 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -594,22 +594,17 @@ async def solve_dependencies( response.status_code = None # type: ignore if dependency_cache is None: dependency_cache = {} + dependency_overrides: Dict[Callable[..., Any], Callable[..., Any]] = getattr( + dependency_overrides_provider, "dependency_overrides", {} + ) for sub_dependant in dependant.dependencies: - sub_dependant.call = cast(Callable[..., Any], sub_dependant.call) - call = sub_dependant.call + call = cast(Callable[..., Any], sub_dependant.call) use_sub_dependant = sub_dependant - if ( - dependency_overrides_provider - and dependency_overrides_provider.dependency_overrides - ): - original_call = sub_dependant.call - call = getattr( - dependency_overrides_provider, "dependency_overrides", {} - ).get(original_call, original_call) - use_path: str = sub_dependant.path # type: ignore + if dependency_overrides and (overridden_call := dependency_overrides.get(call)): + call = overridden_call use_sub_dependant = get_dependant( - path=use_path, - call=call, + path=cast(str, sub_dependant.path), + call=overridden_call, name=sub_dependant.name, parent_oauth_scopes=sub_dependant.oauth_scopes, scope=sub_dependant.scope,