summaryrefslogtreecommitdiff
path: root/tests/backends
diff options
context:
space:
mode:
authorNatalia <124304+nessita@users.noreply.github.com>2025-06-03 15:54:16 -0300
committernessita <124304+nessita@users.noreply.github.com>2025-06-16 17:41:24 -0300
commit1a03a984ab3728253f964ba16cd8d806f76bddf9 (patch)
tree4342bb19065426d7757aadde572ff6a77688a555 /tests/backends
parent104cbfd44b9eff010daf0ef0e1ce434385855b13 (diff)
Fixed #36380 -- Deferred SQL formatting when running tests with --debug-sql.
Thanks to Jacob Walls for the report and previous iterations of this fix, to Simon Charette for the logging formatter idea, and to Tim Graham for testing and ensuring that 3rd party backends remain compatible. This partially reverts d8f093908c504ae0dbc39d3f5231f7d7920dde37. Refs #36112, #35448. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Diffstat (limited to 'tests/backends')
-rw-r--r--tests/backends/tests.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 0e5348e248..5e38f0112d 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -83,12 +83,7 @@ class LastExecutedQueryTest(TestCase):
connection.ops.last_executed_query(cursor, "SELECT %s" + suffix, (1,))
def test_debug_sql(self):
- qs = Reporter.objects.filter(first_name="test")
- ops = connections[qs.db].ops
- with mock.patch.object(ops, "format_debug_sql") as format_debug_sql:
- list(qs)
- # Queries are formatted with DatabaseOperations.format_debug_sql().
- format_debug_sql.assert_called()
+ list(Reporter.objects.filter(first_name="test"))
sql = connection.queries[-1]["sql"].lower()
self.assertIn("select", sql)
self.assertIn(Reporter._meta.db_table, sql)
@@ -580,13 +575,13 @@ class BackendTestCase(TransactionTestCase):
@mock.patch("django.db.backends.utils.logger")
@override_settings(DEBUG=True)
def test_queries_logger(self, mocked_logger):
- sql = "SELECT 1" + connection.features.bare_select_suffix
- sql = connection.ops.format_debug_sql(sql)
+ sql = "select 1" + connection.features.bare_select_suffix
with connection.cursor() as cursor:
cursor.execute(sql)
params, kwargs = mocked_logger.debug.call_args
self.assertIn("; alias=%s", params[0])
self.assertEqual(params[2], sql)
+ self.assertNotEqual(params[2], connection.ops.format_debug_sql(sql))
self.assertIsNone(params[3])
self.assertEqual(params[4], connection.alias)
self.assertEqual(