diff options
| author | Aymeric Augustin | 2013-11-10 23:07:15 +0100 | 
|---|---|---|
| committer | Aymeric Augustin | 2013-11-10 23:18:15 +0100 | 
| commit | 35f90e2644dcb9e49247b80535f3a4e070b8943b (patch) | |
| tree | 0ad193aa21ab4edc0e96e9516b7412003de78661 | |
| parent | 28dac268782b1e9b2c0bce1b9d8aad5fc4673a1d (diff) | |
| download | django-debug-toolbar-35f90e2644dcb9e49247b80535f3a4e070b8943b.tar.bz2 | |
Made enable/disable_instrumentation idempotent.
| -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: | 
