From 3b42821932aa856251fc02333c81a021ad0ecf96 Mon Sep 17 00:00:00 2001 From: Yume05-dev <266928269+Yume05-dev@users.noreply.github.com> Date: Mon, 23 Mar 2026 12:59:41 -0400 Subject: [PATCH] refactor: raise clear ValueError when Depends receives a non-callable --- fastapi/params.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fastapi/params.py b/fastapi/params.py index e8f2eb290d..42444dd0ea 100644 --- a/fastapi/params.py +++ b/fastapi/params.py @@ -748,6 +748,12 @@ class Depends: use_cache: bool = True scope: Literal["function", "request"] | None = None + def __post_init__(self) -> None: + if self.dependency is not None and not callable(self.dependency): + raise ValueError( + f"Dependency must be a callable (function, class, etc.). " + f"Received: {type(self.dependency).__name__}" + ) @dataclass(frozen=True) class Security(Depends):