python config_error ai_generated true

AssertionError: Duplicate route path: /items/{item_id}

ID: python/fastapi-route-order-shadowing

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2026-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Defining two routes with the same path but different methods or parameters, causing a conflict.

generic

中文

定义了具有相同路径但方法或参数不同的两个路由,导致冲突。

Workarounds

  1. 100% success
    Use different paths for different endpoints: /items/{item_id} and /items/{item_id}/details
  2. 90% success
    Combine them into one route and handle logic based on method or query params

Dead Ends

Common approaches that don't work:

  1. 60% fail

    FastAPI checks for duplicates regardless of order.

  2. 80% fail

    If the path is identical, it's still a duplicate.