# fastapi.exceptions.FastAPIError：此依赖项不支持依赖项覆盖。

- **ID:** `python/fastapi-dependency-override`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试覆盖不是函数或可调用的依赖项，或使用了错误的覆盖语法。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100.x | active | — | — |
| 0.110.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   def get_db():
    return 'real'
app.dependency_overrides[get_db] = lambda: 'fake'
   ```
2. **** (85% 成功率)
   ```
   class Dep:
    def __call__(self):
        return 'real'
app.dependency_overrides[Dep()] = lambda: 'fake'
   ```

## 无效尝试

- **** — If dep is not a function, this fails. (60% 失败率)
- **** — Fragile and not recommended. (80% 失败率)
