app.routes contains _IncludedRouter with no .path since 0.137 #15791
-
|
Since 0.137, app.routes can contain _IncludedRouter objects that have no .path attribute. Code that iterates app.routes and reads route.path worked on earlier versions and now raises AttributeError. from fastapi import FastAPI, APIRouter
sub = APIRouter()
@sub.get("/items")
def items():
return {}
app = FastAPI()
app.include_router(sub, prefix="/v1")
[route.path for route in app.routes]
# AttributeError: '_IncludedRouter' object has no attribute 'path'Before 0.137, include_router copied each child route into app.routes, so every entry exposed .path. Now it appends a single _IncludedRouter that matches lazily and has no .path. On a CORS preflight (path matches, method doesn't) it returns a partial match, and a consumer that reads .path on the matched route raises. This has hit a few tools that read .path off app.routes:
Would you want _IncludedRouter to expose .path (the include prefix), matching Route/Mount/Host, or handle it another way? Happy to send a PR. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
Please, see #15782 and PR #15785