Skip to content

Commit b7af52d

Browse files
living180tim-schilling
authored andcommitted
Improve comment in wrap_cursor()
More fully explain the reasoning for skipping monkey patching when running under a Django SimpleTestCase.
1 parent 5d42044 commit b7af52d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

debug_toolbar/panels/sql/tracking.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ class SQLQueryTriggered(Exception):
3333

3434

3535
def wrap_cursor(connection):
36-
# If running a Django SimpleTestCase, which isn't allowed to access the database,
37-
# don't perform any monkey patching.
36+
# When running a SimpleTestCase, Django monkey patches some DatabaseWrapper
37+
# methods, including .cursor() and .chunked_cursor(), to raise an exception
38+
# if the test code tries to access the database, and then undoes the monkey
39+
# patching when the test case is finished. If we monkey patch those methods
40+
# also, Django's process of undoing those monkey patches will fail. To
41+
# avoid this failure, and because database access is not allowed during a
42+
# SimpleTextCase anyway, skip applying our instrumentation monkey patches if
43+
# we detect that Django has already monkey patched DatabaseWrapper.cursor().
3844
if isinstance(connection.cursor, django.test.testcases._DatabaseFailure):
3945
return
4046
if not hasattr(connection, "_djdt_cursor"):

0 commit comments

Comments
 (0)