From 2a78d571e1ccf871724514ee4b955c24fa09e22a Mon Sep 17 00:00:00 2001 From: SASAO Takahiro Date: Tue, 25 Apr 2023 14:50:41 +0900 Subject: [PATCH] Fix codition for bare router in FastAPI ingertaion. WITHOUT TEST CODES. https://github.com/rollbar/pyrollbar/issues/398 --- rollbar/contrib/fastapi/utils.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/rollbar/contrib/fastapi/utils.py b/rollbar/contrib/fastapi/utils.py index 74186133..6566fef3 100644 --- a/rollbar/contrib/fastapi/utils.py +++ b/rollbar/contrib/fastapi/utils.py @@ -67,16 +67,11 @@ def get_installed_middlewares(app): def has_bare_routing(app_or_router): - expected_app_routes = 4 - expected_router_routes = 0 - - if ( - isinstance(app_or_router, FastAPI) - and expected_app_routes != len(app_or_router.routes) - ) or ( - isinstance(app_or_router, APIRouter) - and expected_router_routes != len(app_or_router.routes) - ): - return False + def is_internal(route): + return route.endpoint.__qualname__.startswith("FastAPI.setup.") + + if isinstance(app_or_router, (FastAPI, APIRouter)): + if 0 < len([ r for r in app_or_router.routes if not is_internal(r) ]): + return False return True