diff options
Diffstat (limited to 'debug_toolbar')
| -rw-r--r-- | debug_toolbar/panels/__init__.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/panels/cache.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/panels/sql.py | 10 |
3 files changed, 9 insertions, 5 deletions
diff --git a/debug_toolbar/panels/__init__.py b/debug_toolbar/panels/__init__.py index 9586e80..e60a5e6 100644 --- a/debug_toolbar/panels/__init__.py +++ b/debug_toolbar/panels/__init__.py @@ -51,7 +51,7 @@ class DebugPanel(object): """Title showing in panel""" raise NotImplementedError - # Enable and disable (expensive) instrumentation + # Enable and disable (expensive) instrumentation, must be idempotent def enable_instrumentation(self): pass diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py index a6b06ce..831eacb 100644 --- a/debug_toolbar/panels/cache.py +++ b/debug_toolbar/panels/cache.py @@ -202,7 +202,7 @@ class CacheDebugPanel(DebugPanel): def enable_instrumentation(self): # This isn't thread-safe because cache connections aren't thread-local # in Django, unlike database connections. - cache.cache = CacheStatTracker(cache.cache) + cache.cache = CacheStatTracker(original_cache) cache.get_cache = get_cache def disable_instrumentation(self): 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: |
