From 936c1f415e93dcbb651501352be9d3a68d43b90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 1 Nov 2025 15:02:17 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Improve=20the=20error=20fo?= =?UTF-8?q?r=20broken=20scopes=20in=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/dependencies/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index dfe76e1c0..c5c6b69bb 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -266,9 +266,10 @@ def get_dependant( and dependant.computed_scope == "request" and param_details.depends.scope == "function" ): + assert dependant.call raise DependencyScopeError( - f'The dependency {dependant} has a scope of "request", it' - 'cannot depend on dependencies with scope "function".' + f'The dependency "{dependant.call.__name__}" has a scope of ' + '"request", it cannot depend on dependencies with scope "function".' ) use_security_scopes = security_scopes or [] if isinstance(param_details.depends, params.Security):