python config_error ai_generated true

AssertionError: Route order matters, overlapping routes detected

ID: python/starlette-route-order-shadowing

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2024-07-28First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Defining a catch-all or parameterized route before a specific route causes shadowing.

generic

中文

在特定路由之前定义了通配符或参数化路由,导致遮蔽。

Workarounds

  1. 95% success
    Define specific routes first: routes = [
        Route('/users/me', me),
        Route('/users/{user_id}', user),
    ]
  2. 90% success
    Use path converters with constraints: Route('/files/{path:path}', file_handler)

Dead Ends

Common approaches that don't work:

  1. 50% fail

    Loses functionality; should reorder instead.

  2. 60% fail

    Regex may still match broader patterns.