# FastAPI错误：函数中参数名重复

- **ID:** `python/fastapi-duplicate-route-registration`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在单个路由处理函数中定义多个同名路径参数（如`@app.get('/items/{item_id}')`并在函数签名中重复使用`item_id`）会导致重复参数错误。

## 版本兼容性

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

## 解决方案

1. **** (100% 成功率)
   ```
   Ensure each path parameter appears only once in the function signature. Example: `def read_item(item_id: int, q: str = None):`
   ```
2. **** (95% 成功率)
   ```
   Use distinct names for path and query parameters, e.g., `def read_item(item_id: int, query_param: str = None):`
   ```

## 无效尝试

- **** — Renaming the parameter in the function signature but not in the path decorator causes a mismatch and still raises an error. (80% 失败率)
- **** — Using type hints like `item_id: int` doesn't resolve the duplicate; FastAPI still sees two parameters with the same name. (90% 失败率)
