python config_error ai_generated true

断言错误:重复的路由路径:/items/{item_id}

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

ID: python/fastapi-route-order-shadowing

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2026-01-10首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 60% 失败

    FastAPI checks for duplicates regardless of order.

  2. 80% 失败

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