Skip to content

Commit e806603

Browse files
committed
Fixed issue #230 -- Avoid queries in aborted transactions
On PostgreSQL when the transaction is in aborted status, checking connection.isolation_level will result in an error.
1 parent 1258e75 commit e806603

File tree

1 file changed

+8
-1
lines changed
  • debug_toolbar/utils/tracking

1 file changed

+8
-1
lines changed

debug_toolbar/utils/tracking/db.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,17 @@ def execute(self, sql, params=()):
146146
}
147147

148148
if engine == 'psycopg2':
149+
# If an erroneous query was ran on the connection, it might
150+
# be in a state where checking isolation_level raises an
151+
# exception.
152+
try:
153+
iso_level = conn.isolation_level
154+
except conn.InternalError:
155+
iso_level = 'unknown'
149156
params.update({
150157
'trans_id': self.logger.get_transaction_id(alias),
151158
'trans_status': conn.get_transaction_status(),
152-
'iso_level': conn.isolation_level,
159+
'iso_level': iso_level,
153160
'encoding': conn.encoding,
154161
})
155162

0 commit comments

Comments
 (0)