FastAPI 0.137.0 has been released with a significant internal refactor that changes how routers and routes are handled behind the scenes. Previously, when you used router.include_router(other_router), each path operation from the included router was cloned or recreated, resulting in a single top-level router. The new design introduces intermediate metadata classes that store the inclusion hierarchy (router X includes Y includes Z) without duplicating or recreating the actual route objects. This means router.routes may now contain these intermediate objects instead of plain APIRoute instances—a breaking change if your code directly inspects router.routes.
- Break change:
router.routesmay now hold intermediate metadata objects, not justAPIRouteinstances. - Foundation: This refactor "unblocks SO MANY THINGS," enabling future features like dependencies that execute for 404 responses within a nested router.
- Not included: Support for router-level dependencies on 404 was explicitly excluded due to complexity—a router that didn't match the request should not consume the request body or run dependencies.
- Backward compatibility: For most FastAPI users, upgrading should be seamless unless you manipulate
router.routesdirectly.
Why does this matter? Preserving the original router instances opens the door for advanced features. However, developers must adapt any code that depends on router.routes being a plain list of APIRoute. This release lays the groundwork for richer router behaviors to come.
Check your code for any direct manipulation of router.routes and update accordingly.
Source: https://github.com/fastapi/fastapi/releases/tag/0.137.0