python
runtime_error
ai_generated
true
fastapi.exceptions.FastAPIError: Dependency overrides are not supported for this dependency.
ID: python/fastapi-dependency-override
80%Fix Rate
87%Confidence
0Evidence
2025-05-25First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100.x | active | — | — | — |
| 0.110.x | active | — | — | — |
Root Cause
Attempting to override a dependency that is not a function or callable, or using incorrect override syntax.
generic中文
尝试覆盖不是函数或可调用的依赖项,或使用了错误的覆盖语法。
Workarounds
-
95% success
def get_db(): return 'real' app.dependency_overrides[get_db] = lambda: 'fake' -
85% success
class Dep: def __call__(self): return 'real' app.dependency_overrides[Dep()] = lambda: 'fake'
Dead Ends
Common approaches that don't work:
-
60% fail
If dep is not a function, this fails.
-
80% fail
Fragile and not recommended.