From 35f90e2644dcb9e49247b80535f3a4e070b8943b Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 10 Nov 2013 23:07:15 +0100 Subject: Made enable/disable_instrumentation idempotent. --- debug_toolbar/panels/sql.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'debug_toolbar/panels/sql.py') 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: -- cgit v1.2.3