# RuntimeWarning: 协程 'get_db' 从未被 await

- **ID:** `python/fastapi-depends-async-generator-not-closed`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

异步依赖（async def 或异步生成器）被当作普通函数使用，或漏写 Depends 导致返回未 await 的协程。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   Declare the dependency with Depends:
def route(db=Depends(get_db)): ...
   ```
2. **** (88% 成功率)
   ```
   Use an async generator dependency that yields and cleans up in finally.
   ```

## 无效尝试

- **** — Blocks the event loop and may break async DB drivers. (60% 失败率)
- **** — Returns a coroutine/generator you then misuse; resources leak. (80% 失败率)
