File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515from debug_toolbar .api import render_panel
1616from debug_toolbar .settings import DebugToolbarSettings
1717from debug_toolbar .toolbar import DebugToolbar
18- from debug_toolbar .utils import import_string
18+ from debug_toolbar .utils import import_string , matched_route
1919
2020
2121def show_toolbar (request : Request , settings : DebugToolbarSettings ) -> bool :
@@ -60,8 +60,11 @@ async def dispatch(
6060 request : Request ,
6161 call_next : RequestResponseEndpoint ,
6262 ) -> Response :
63+ request .scope ["route" ] = matched_route (request )
64+
6365 if (
64- not self .show_toolbar (request , self .settings )
66+ not request .scope ["route" ]
67+ or not self .show_toolbar (request , self .settings )
6568 or self .settings .API_URL in request .url .path
6669 ):
6770 return await call_next (request )
Original file line number Diff line number Diff line change 77
88from debug_toolbar .panels import Panel
99from debug_toolbar .types import Stats
10- from debug_toolbar .utils import is_coroutine , matched_endpoint , pluralize
10+ from debug_toolbar .utils import is_coroutine , pluralize
1111
1212try :
1313 import threading
@@ -92,12 +92,7 @@ def nav_subtitle(self) -> str:
9292 return f"{ record_count } message{ pluralize (record_count )} "
9393
9494 async def process_request (self , request : Request ) -> Response :
95- endpoint = matched_endpoint (request )
96-
97- if endpoint is None :
98- return await super ().process_request (request )
99-
100- if is_coroutine (endpoint ):
95+ if is_coroutine (request .scope ["route" ].endpoint ):
10196 self .thread_id = threading .get_ident ()
10297 else :
10398 self .thread_id = await run_in_threadpool (threading .get_ident )
Original file line number Diff line number Diff line change 66
77from debug_toolbar .panels import Panel
88from debug_toolbar .types import Stats
9- from debug_toolbar .utils import is_coroutine , matched_endpoint
9+ from debug_toolbar .utils import is_coroutine
1010
1111
1212class ProfilingPanel (Panel ):
@@ -15,12 +15,7 @@ class ProfilingPanel(Panel):
1515
1616 async def process_request (self , request : Request ) -> Response :
1717 self .profiler = Profiler (** self .toolbar .settings .PROFILER_OPTIONS )
18- endpoint = matched_endpoint (request )
19-
20- if endpoint is None :
21- return await super ().process_request (request )
22-
23- is_async = is_coroutine (endpoint )
18+ is_async = is_coroutine (request .scope ["route" ].endpoint )
2419
2520 async def call (func : t .Callable ) -> None :
2621 await run_in_threadpool (func ) if not is_async else func ()
Original file line number Diff line number Diff line change 44from fastapi import Request , Response
55from fastapi .concurrency import AsyncExitStack
66from fastapi .dependencies .utils import solve_dependencies
7- from fastapi .routing import APIRoute
87from sqlalchemy import event
98from sqlalchemy .engine import Connection , Engine
109from sqlalchemy .engine .default import DefaultExecutionContext
1110from sqlalchemy .orm import Session
1211
1312from debug_toolbar .panels .sql import SQLPanel
14- from debug_toolbar .utils import matched_route
1513
1614
1715class SQLAlchemyPanel (SQLPanel ):
@@ -55,11 +53,9 @@ def after_execute(
5553
5654 async def process_request (self , request : Request ) -> Response :
5755 engines : t .Set [Engine ] = set ()
58- route = matched_route ( request )
56+ route = request . scope [ "route" ]
5957
6058 if hasattr (route , "dependant" ):
61- route = t .cast (APIRoute , route )
62-
6359 if request .scope .get ("fastapi_astack" ) is None :
6460 async with AsyncExitStack () as stack :
6561 request .scope ["fastapi_astack" ] = stack
Original file line number Diff line number Diff line change 88from fastapi .routing import APIRoute
99from pydantic .color import Color
1010from starlette .routing import Match
11- from starlette .staticfiles import StaticFiles
1211
1312
1413def import_string (import_name : str ) -> t .Any :
@@ -43,20 +42,11 @@ def get_name_from_obj(obj: t.Any) -> str:
4342def matched_route (request : Request ) -> t .Optional [APIRoute ]:
4443 for route in request .app .routes :
4544 match , _ = route .matches (request .scope )
46- if match == Match .FULL :
47- return route
48- return None
49-
5045
51- def matched_endpoint (request : Request ) -> t .Optional [t .Callable ]:
52- route = matched_route (request )
53- if route is not None :
54- endpoint = getattr (route , "endpoint" , None )
55-
56- if endpoint is not None :
57- return endpoint
58- if not isinstance (route .app , StaticFiles ):
59- return route .app
46+ if match == Match .FULL :
47+ if hasattr (route , "endpoint" ):
48+ return route
49+ break
6050 return None
6151
6252
You can’t perform that action at this time.
0 commit comments