python config_error ai_generated true

ValueError: Duplicate param name 'item_id' in path operation

ID: python/starlette-path-operation-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-08-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Multiple path parameters in a route have the same name, causing ambiguity.

generic

中文

路由中的多个路径参数具有相同的名称,导致歧义。

Workarounds

  1. 95% success 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):
        ...
  2. 85% success Combine parameters into a single path segment
    @app.route('/items/{item_id}')
    async def get_item(item_id: str):
        ...

Dead Ends

Common approaches that don't work:

  1. Removing one of the parameters without adjusting the route 80% fail

    Breaks the route logic; URL pattern becomes incorrect.

  2. Using different variable names but same path segment 90% fail

    Starlette still sees duplicate path parameters.