Commit 32ab363
committed
Fix psycopg3 tests
Several tests (such as SQLPanelTestCase.test_cursor_wrapper_singleton)
are written to ensure that only a single cursor wrapper is instantiated
during the test. However, this fails when using Django's psycopg3
backend, since the .last_executed_query() call in
NormalCursorWrapper._record() ends up creating an additional cursor (via
[1]). To avoid this wrapping this additional cursor, set the
DatabaseWrapper's ._djdt_logger attribute to None before calling
.last_executed_query() and restore it when finished. This will cause
the monkey-patched DatabaseWrapper .cursor() and .chunked_cursor()
methods to return the original cursor without wrapping during that call.
[1] https://github.com/django/django/blob/4.2.1/django/db/backends/postgresql/psycopg_any.py#L211 parent 217238b commit 32ab363
1 file changed
+19
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
147 | 162 | | |
148 | 163 | | |
149 | 164 | | |
| |||
176 | 191 | | |
177 | 192 | | |
178 | 193 | | |
179 | | - | |
180 | | - | |
181 | | - | |
| 194 | + | |
182 | 195 | | |
183 | 196 | | |
184 | 197 | | |
185 | 198 | | |
186 | 199 | | |
187 | 200 | | |
188 | 201 | | |
189 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
190 | 205 | | |
191 | 206 | | |
192 | 207 | | |
| |||
0 commit comments