Skip to content

fix: handle FastAPI >= 0.137 lazy router inclusion (_IncludedRouter)#64

Open
fsecada01 wants to merge 1 commit into
mongkok:mainfrom
fsecada01:fix/fastapi-0137-included-router
Open

fix: handle FastAPI >= 0.137 lazy router inclusion (_IncludedRouter)#64
fsecada01 wants to merge 1 commit into
mongkok:mainfrom
fsecada01:fix/fastapi-0137-included-router

Conversation

@fsecada01

Copy link
Copy Markdown

FastAPI 0.137 introduced lazy router inclusion: include_router() now appends an internal _IncludedRouter node (a BaseRoute with no .path) to app.routes instead of eagerly flattening included routes. The toolbar iterated app.routes assuming every entry was a concrete route, so:

  • matched_route() called route.matches() and the RoutesPanel template read route.path on _IncludedRouter nodes, raising AttributeError: '_IncludedRouter' object has no attribute 'path' on every request once the toolbar was active.

Adds utils.iter_effective_routes(), which expands _IncludedRouter nodes into their effective, correctly-prefixed route contexts (each exposing .path/.name/.methods/.endpoint and a working .matches) and is a no-op on older FastAPI. matched_route() and RoutesPanel now flatten via this helper; matched_route() returns the underlying original_route for expanded contexts.

FastAPI 0.137 introduced lazy router inclusion: include_router() now appends
an internal _IncludedRouter node (a BaseRoute with no .path) to app.routes
instead of eagerly flattening included routes. The toolbar iterated
app.routes assuming every entry was a concrete route, so:

- matched_route() called route.matches() and the RoutesPanel template read
  route.path on _IncludedRouter nodes, raising
  AttributeError: '_IncludedRouter' object has no attribute 'path'
  on every request once the toolbar was active.

Adds utils.iter_effective_routes(), which expands _IncludedRouter nodes into
their effective, correctly-prefixed route contexts (each exposing
.path/.name/.methods/.endpoint and a working .matches) and is a no-op on
older FastAPI. matched_route() and RoutesPanel now flatten via this helper;
matched_route() returns the underlying original_route for expanded contexts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fsecada01 fsecada01 force-pushed the fix/fastapi-0137-included-router branch from 91769a6 to 8c6d16a Compare June 17, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant