Skip to content

Fix FastAPI >= 0.137.0 compatibility with _IncludedRouter in route template resolution#107

Open
tpatzelt wants to merge 1 commit into
claws:masterfrom
tpatzelt:fix/fastapi-included-router-compat
Open

Fix FastAPI >= 0.137.0 compatibility with _IncludedRouter in route template resolution#107
tpatzelt wants to merge 1 commit into
claws:masterfrom
tpatzelt:fix/fastapi-included-router-compat

Conversation

@tpatzelt

Copy link
Copy Markdown

FastAPI >= 0.137.0 refactored include_router() to insert _IncludedRouter nodes into app.routes. These nodes have no .path attribute, causing AttributeError in get_full_or_template_path.

Changes

  • _match_route_template: New recursive method that walks _IncludedRouter nodes via original_router.routes to preserve template URL support for included routes.
  • get_full_or_template_path: Delegates to _match_route_template instead of directly iterating routes.
  • Tests: Adds tests/test_fastapi_compat.py with three test cases covering included routers with MetricsMiddleware.

…stAPI >= 0.137.0

FastAPI >= 0.137.0 refactored include_router() to insert _IncludedRouter
nodes into app.routes. These nodes have no .path attribute, causing
AttributeError in get_full_or_template_path. Recursively walk their
children via original_router.routes to preserve template URL support.

Adds test coverage for included routers with the MetricsMiddleware.
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