# 类型错误：缺少1个必需的位置参数：'db'

- **ID:** `python/fastapi-depends-missing-parameter`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

依赖函数期望一个参数，但调用方或依赖注入系统未提供。

## 版本兼容性

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

## 解决方案

1. **Ensure the dependency is properly injected using Depends** (95% 成功率)
   ```
   from fastapi import Depends
async def get_db():
    return db
@app.get('/items')
async def read_items(db=Depends(get_db)):
   ```
2. **Define the dependency as a class with __call__** (85% 成功率)
   ```
   class DBSession:
    def __call__(self):
        return db
@app.get('/items')
async def read_items(db=Depends(DBSession())):
   ```

## 无效尝试

- **Adding a default value to the parameter** — May not solve the underlying issue if the dependency is required. (50% 失败率)
- **Removing the dependency from the route** — Breaks the functionality that requires the dependency. (80% 失败率)
