|
11 | 11 | from debug_toolbar.panels.sql.forms import SQLSelectForm
|
12 | 12 | from debug_toolbar.utils import render_stacktrace
|
13 | 13 | from debug_toolbar.panels.sql.utils import reformat_sql
|
14 |
| -from debug_toolbar.panels.sql.tracking import CursorWrapper |
| 14 | +from debug_toolbar.panels.sql.tracking import wrap_cursor, unwrap_cursor |
15 | 15 |
|
16 | 16 |
|
17 | 17 | def get_isolation_level_display(engine, level):
|
@@ -128,16 +128,11 @@ def title(self):
|
128 | 128 | def enable_instrumentation(self):
|
129 | 129 | # This is thread-safe because database connections are thread-local.
|
130 | 130 | for connection in connections.all():
|
131 |
| - if not hasattr(connection, '_djdt_cursor'): |
132 |
| - connection._djdt_cursor = connection.cursor |
133 |
| - connection.cursor = lambda: CursorWrapper( |
134 |
| - connection._djdt_cursor(), connection, self) |
| 131 | + wrap_cursor(connection, self) |
135 | 132 |
|
136 | 133 | def disable_instrumentation(self):
|
137 | 134 | for connection in connections.all():
|
138 |
| - if hasattr(connection, '_djdt_cursor'): |
139 |
| - del connection._djdt_cursor |
140 |
| - del connection.cursor |
| 135 | + unwrap_cursor(connection) |
141 | 136 |
|
142 | 137 | def process_response(self, request, response):
|
143 | 138 | if self._queries:
|
|
0 commit comments