Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
psycopg2: Avoid causing a 2nd error in an aborted transaction
Asking for connection isolation_level results in a query executed by
psycopg2. However, all queries ran in an aborted transaction will result
in a new error.

This is my biggest annoyance with the debug toolbar -- whenever a query
causes an aborted transaction, the original error is hidden and a new
exception is thrown:

  InternalError: current transaction is aborted, commands ignored until
  end of transaction block
  • Loading branch information
intgr committed Oct 24, 2012
commit 84ad67ec0d343ae5d3b7902fd059ba967a8bb39e
8 changes: 7 additions & 1 deletion debug_toolbar/utils/tracking/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,16 @@ def execute(self, sql, params=()):
params.update({
'trans_id': self.logger.get_transaction_id(alias),
'trans_status': conn.get_transaction_status(),
'iso_level': conn.isolation_level,
'encoding': conn.encoding,
})

# This fails when a query aborted the transaction. Avoid
# causing a 2nd exception and hiding the real error
try:
params['iso_level'] = conn.isolation_level
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't specify exception?

pass

# We keep `sql` to maintain backwards compatibility
self.logger.record(**params)

Expand Down