Skip to content

Commit 9237148

Browse files
committed
Add SQLAlchemyPanel.add_bind method
1 parent 60fb7b1 commit 9237148

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

debug_toolbar/panels/sqlalchemy.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import typing as t
24
from contextlib import AsyncExitStack
35
from time import perf_counter
@@ -41,13 +43,13 @@ def after_execute(self, context: ExecutionContext, **kwargs: t.Any) -> None:
4143
}
4244
self.add_query(str(context.engine.url), query)
4345

44-
async def add_engines(self, request: Request): # noqa: C901
45-
def add_bind_to_engines(bind: t.Union[Connection, Engine]):
46-
if isinstance(bind, Connection):
47-
self.engines.add(bind.engine)
48-
else:
49-
self.engines.add(bind)
46+
def add_bind(self, bind: Connection | Engine):
47+
if isinstance(bind, Connection):
48+
self.engines.add(bind.engine)
49+
else:
50+
self.engines.add(bind)
5051

52+
async def add_engines(self, request: Request): # noqa: C901
5153
route = request["route"]
5254

5355
if hasattr(route, "dependant"):
@@ -68,10 +70,10 @@ def add_bind_to_engines(bind: t.Union[Connection, Engine]):
6870
binds = getattr(value, "_Session__binds", None)
6971
if binds:
7072
for bind in binds.values():
71-
add_bind_to_engines(bind)
73+
self.add_bind(bind)
7274
else:
7375
bind = value.get_bind()
74-
add_bind_to_engines(bind)
76+
self.add_bind(bind)
7577

7678
async def process_request(self, request: Request) -> Response:
7779
await self.add_engines(request)

0 commit comments

Comments
 (0)