python
config_error
ai_generated
true
AssertionError: Duplicate route path: /items/{item_id}
ID: python/fastapi-route-order-shadowing
80%Fix Rate
83%Confidence
0Evidence
2026-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Defining two routes with the same path but different methods or parameters, causing a conflict.
generic中文
定义了具有相同路径但方法或参数不同的两个路由,导致冲突。
Workarounds
-
100% success
Use different paths for different endpoints: /items/{item_id} and /items/{item_id}/details -
90% success
Combine them into one route and handle logic based on method or query params
Dead Ends
Common approaches that don't work:
-
60% fail
FastAPI checks for duplicates regardless of order.
-
80% fail
If the path is identical, it's still a duplicate.