mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
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 d8f093908c.
Refs #36112, #35448.
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
This commit is contained in:
parent
104cbfd44b
commit
1a03a984ab
4 changed files with 216 additions and 28 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue