From 330d89d4fe7832355535580383523f1749a3ee45 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 25 Jan 2025 12:06:11 -0500 Subject: [PATCH] Fixed #36111 -- Fixed test --debug-sql crash on Oracle when no prior query has executed. --- django/db/backends/oracle/operations.py | 2 +- tests/backends/tests.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py index aa67f28a79..7c8c015f45 100644 --- a/django/db/backends/oracle/operations.py +++ b/django/db/backends/oracle/operations.py @@ -319,7 +319,7 @@ END; # Unlike Psycopg's `query` and MySQLdb`'s `_executed`, oracledb's # `statement` doesn't contain the query parameters. Substitute # parameters manually. - if params: + if statement and params: if isinstance(params, (tuple, list)): params = { f":arg{i}": param for i, param in enumerate(dict.fromkeys(params)) diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 0349e47272..4ba961bfc1 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -73,8 +73,14 @@ class LastExecutedQueryTest(TestCase): last_executed_query should not raise an exception even if no previous query has been run. """ + suffix = connection.features.bare_select_suffix with connection.cursor() as cursor: + if connection.vendor == "oracle": + cursor.statement = None + # No previous query has been run. connection.ops.last_executed_query(cursor, "", ()) + # Previous query crashed. + connection.ops.last_executed_query(cursor, "SELECT %s" + suffix, (1,)) def test_debug_sql(self): qs = Reporter.objects.filter(first_name="test")