Skip to content

Commit 0333418

Browse files
committed
Handle db aliases which are not defined in connections
1 parent 98c4ec3 commit 0333418

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

debug_toolbar/panels/sql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ def __init__(self, *args, **kwargs):
7777
self._transaction_ids = {}
7878

7979
def get_transaction_id(self, alias):
80+
if alias not in connections:
81+
return
8082
conn = connections[alias].connection
8183
if not conn:
82-
return None
84+
return
8385

8486
engine = conn.__class__.__module__.split('.', 1)[0]
8587
if engine == 'psycopg2':

debug_toolbar/utils/tracking/db.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ def execute(self, sql, params=()):
102102
try:
103103
return self.cursor.execute(sql, params)
104104
finally:
105-
# FIXME: Sometimes connections which are not in the connections
106-
# dict are used (for example in test database destroying).
107-
# The code below (at least get_transaction_id(alias) needs to have
108-
# the connection in the connections dict. It would be good to
109-
# not have this requirement at all, but for now lets just skip
110-
# these connections.
111-
if self.db.alias not in connections:
112-
return
113105
stop = datetime.now()
114106
duration = ms_from_timedelta(stop - start)
115107
enable_stacktraces = getattr(settings,
@@ -149,8 +141,8 @@ def execute(self, sql, params=()):
149141
params = {
150142
'engine': engine,
151143
'alias': alias,
152-
'sql': self.db.ops.last_executed_query(self.cursor, sql,
153-
self._quote_params(params)),
144+
'sql': self.db.ops.last_executed_query(
145+
self.cursor, sql, self._quote_params(params)),
154146
'duration': duration,
155147
'raw_sql': sql,
156148
'params': _params,

0 commit comments

Comments
 (0)