python
runtime_error
ai_generated
true
fastapi.exceptions.FastAPIError:此依赖项不支持依赖项覆盖。
fastapi.exceptions.FastAPIError: Dependency overrides are not supported for this dependency.
ID: python/fastapi-dependency-override
80%修复率
87%置信度
0证据数
2025-05-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100.x | active | — | — | — |
| 0.110.x | active | — | — | — |
根因分析
尝试覆盖不是函数或可调用的依赖项,或使用了错误的覆盖语法。
English
Attempting to override a dependency that is not a function or callable, or using incorrect override syntax.
解决方案
-
95% 成功率
def get_db(): return 'real' app.dependency_overrides[get_db] = lambda: 'fake' -
85% 成功率
class Dep: def __call__(self): return 'real' app.dependency_overrides[Dep()] = lambda: 'fake'
无效尝试
常见但无效的做法:
-
60% 失败
If dep is not a function, this fails.
-
80% 失败
Fragile and not recommended.