Skip to content

fix(fastapi): handle FastAPI 0.137 _IncludedRouter route type#122

Merged
lesnik512 merged 1 commit into
mainfrom
fix/fastapi-0137-included-router
Jun 14, 2026
Merged

fix(fastapi): handle FastAPI 0.137 _IncludedRouter route type#122
lesnik512 merged 1 commit into
mainfrom
fix/fastapi-0137-included-router

Conversation

@lesnik512

@lesnik512 lesnik512 commented Jun 14, 2026

Copy link
Copy Markdown
Member

Problem

CI on main went red across all Python versions. just install runs uv lock --upgrade, which pulled FastAPI 0.137.0. That release introduced an internal _IncludedRouter route type (a BaseRoute subclass with no .path) into app.router.routes, and two places read route.path unconditionally:

  1. Our codelite_bootstrap/helpers/fastapi_helpers.py did typing.cast(Route, route).path. The cast is a runtime no-op, so it raised AttributeError: '_IncludedRouter' object has no attribute 'path'.
  2. prometheus-fastapi-instrumentator 8.0.0 (latest, third-party) — same unguarded route.path access. No upstream fix released yet.

Changes

  • fastapi_helpers.py — filter the offline-docs routes by matching only real Route instances (isinstance(route, Route) and route.path in replaced_urls), leaving _IncludedRouter and other route types untouched. Correct on both old and new FastAPI, so nothing to revert when the cap lifts. Dropped the now-unused import typing.
  • pyproject.toml — added fastapi<0.137 to the base fastapi extra (the single source every other fastapi-* extra composes from), so the whole FastAPI surface resolves to a version tested end-to-end and there's no version skew between extras. Comment links the upstream issue.

The cap is temporary, tied to upstream trallnag/prometheus-fastapi-instrumentator#370; lift it once a fixed instrumentator ships.

Verification

  • just test194 passed, 100% coverage
  • just lint-ci → eof-fixer, ruff format, ruff check, ty all clean

🤖 Generated with Claude Code

FastAPI 0.137.0 introduced the internal `_IncludedRouter` route type
(a `BaseRoute` subclass with no `.path`) into `app.router.routes`,
which broke the offline-docs helper that read `route.path` on every
route via an unchecked `typing.cast(Route, route)`.

Filter the docs routes by matching only real `Route` instances, leaving
`_IncludedRouter` and other route types untouched (works on old and new
FastAPI alike). Drop the now-unused `import typing`.

`prometheus-fastapi-instrumentator` (<=8.0.0) has the same unguarded
`route.path` access and is not yet fixed upstream, so cap `fastapi<0.137`
in the `fastapi-metrics` extra until a fixed instrumentator ships.
Upstream issue: trallnag/prometheus-fastapi-instrumentator#370

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 force-pushed the fix/fastapi-0137-included-router branch from 908c14f to fcfcaf0 Compare June 14, 2026 19:42
@lesnik512 lesnik512 merged commit 9aefccd into main Jun 14, 2026
7 checks passed
@lesnik512 lesnik512 deleted the fix/fastapi-0137-included-router branch June 14, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant