Fixed #35021 -- Fixed capturing queries when using client-side parameters binding with psycopg 3+.

This commit is contained in:
Michail Chatzis 2024-02-02 14:38:30 +02:00 committed by Mariusz Felisiak
parent 177e649396
commit 4426b1a72d
4 changed files with 30 additions and 3 deletions

View file

@ -211,6 +211,16 @@ class ExecuteWrapperTests(TestCase):
self.assertEqual(connection.execute_wrappers, [])
self.assertEqual(connections["other"].execute_wrappers, [])
def test_wrapper_debug(self):
def wrap_with_comment(execute, sql, params, many, context):
return execute(f"/* My comment */ {sql}", params, many, context)
with CaptureQueriesContext(connection) as ctx:
with connection.execute_wrapper(wrap_with_comment):
list(Person.objects.all())
last_query = ctx.captured_queries[-1]["sql"]
self.assertTrue(last_query.startswith("/* My comment */"))
class ConnectionHealthChecksTests(SimpleTestCase):
databases = {"default"}