Skip to content

Commit ba501f1

Browse files
committed
Added tortoise-orm >= 0.19.0 support
1 parent 70b5ea4 commit ba501f1

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

debug_toolbar/panels/tortoise.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
from fastapi import Request, Response
66
from tortoise.backends.base.client import BaseDBAsyncClient
7-
from tortoise.transactions import current_transaction_map
7+
8+
try:
9+
from tortoise.connection import connections
10+
except ImportError:
11+
connections = None # type: ignore
812

913
from debug_toolbar.panels.sql import SQLPanel, raw_sql
1014

@@ -70,11 +74,14 @@ def on_execute(
7074
self.add_query(db.connection_name, query)
7175

7276
async def process_request(self, request: Request) -> Response:
73-
for db in current_transaction_map.values():
74-
db.set(DBWrapper(db.get(), self.on_execute))
77+
assert connections is not None, "tortoise-orm >= 0.19.0 is required"
78+
79+
for conn in connections.all():
80+
db = DBWrapper(conn, self.on_execute)
81+
connections.set(conn.connection_name, db) # type: ignore
7582
try:
7683
response = await super().process_request(request)
7784
finally:
78-
for db in current_transaction_map.values():
79-
db.set(db.get().db)
85+
for conn in connections.all():
86+
connections.set(conn.connection_name, conn.db) # type: ignore
8087
return response

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test = [
6969
"pytest-cov",
7070
"python-multipart",
7171
"SQLAlchemy",
72-
"tortoise-orm ==0.15.19",
72+
"tortoise-orm >=0.19.0",
7373
"types-setuptools",
7474
]
7575

0 commit comments

Comments
 (0)