File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -33,8 +33,14 @@ class SQLQueryTriggered(Exception):
33
33
34
34
35
35
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().
38
44
if isinstance (connection .cursor , django .test .testcases ._DatabaseFailure ):
39
45
return
40
46
if not hasattr (connection , "_djdt_cursor" ):
You can’t perform that action at this time.
0 commit comments