python
config_error
ai_generated
true
值错误:路径操作中存在重复的参数名称'item_id'
ValueError: Duplicate param name 'item_id' in path operation
ID: python/starlette-path-operation-conflict
80%修复率
83%置信度
0证据数
2024-08-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
路由中的多个路径参数具有相同的名称,导致歧义。
English
Multiple path parameters in a route have the same name, causing ambiguity.
解决方案
-
95% 成功率 Rename one of the path parameters to be unique
@app.route('/items/{item_id}/details/{detail_id}') async def get_detail(item_id: str, detail_id: str): ... -
85% 成功率 Combine parameters into a single path segment
@app.route('/items/{item_id}') async def get_item(item_id: str): ...
无效尝试
常见但无效的做法:
-
Removing one of the parameters without adjusting the route
80% 失败
Breaks the route logic; URL pattern becomes incorrect.
-
Using different variable names but same path segment
90% 失败
Starlette still sees duplicate path parameters.