Skip to content

Commit

Permalink
Fix codition for bare router in FastAPI ingertaion.
Browse files Browse the repository at this point in the history
WITHOUT TEST CODES.
rollbar#398
  • Loading branch information
tsasao committed Apr 25, 2023
1 parent fd15c2a commit 2a78d57
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions rollbar/contrib/fastapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2a78d57

Please sign in to comment.