aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/sql.py
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-10 23:07:15 +0100
committerAymeric Augustin2013-11-10 23:18:15 +0100
commit35f90e2644dcb9e49247b80535f3a4e070b8943b (patch)
tree0ad193aa21ab4edc0e96e9516b7412003de78661 /debug_toolbar/panels/sql.py
parent28dac268782b1e9b2c0bce1b9d8aad5fc4673a1d (diff)
downloaddjango-debug-toolbar-35f90e2644dcb9e49247b80535f3a4e070b8943b.tar.bz2
Made enable/disable_instrumentation idempotent.
Diffstat (limited to 'debug_toolbar/panels/sql.py')
-rw-r--r--debug_toolbar/panels/sql.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index 53b9f53..1ccdc47 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -119,12 +119,16 @@ class SQLDebugPanel(DebugPanel):
def enable_instrumentation(self):
# This is thread-safe because database connections are thread-local.
for connection in connections.all():
- old_cursor = connection.cursor
- connection.cursor = lambda: CursorWrapper(old_cursor(), connection, self)
+ if not hasattr(connection, '_djdt_cursor'):
+ connection._djdt_cursor = connection.cursor
+ connection.cursor = lambda: CursorWrapper(
+ connection._djdt_cursor(), connection, self)
def disable_instrumentation(self):
for connection in connections.all():
- del connection.cursor
+ if hasattr(connection, '_djdt_cursor'):
+ del connection._djdt_cursor
+ del connection.cursor
def process_response(self, request, response):
if self._queries: