﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36111	--debug-sql fails on Oracle if a query with params fails to execute and no prior query has either	Jacob Walls	Jacob Walls	"Noticed while working on ticket:35972 that an Oracle failure I wanted to debug with `--debug-sql` failed like:

{{{#!py
======================================================================
ERROR: test_last_executed_query_without_previous_query (backends.tests.LastExecutedQueryTest)
last_executed_query should not raise an exception even if no previous
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/django/source/tests/backends/tests.py"", line 80, in test_last_executed_query_without_previous_query
    connection.ops.last_executed_query(cursor, ""SELECT %s;"", (1,))
  File ""/django/source/django/db/backends/oracle/operations.py"", line 330, in last_executed_query
    statement = statement.replace(
AttributeError: 'NoneType' object has no attribute 'replace'
}}}

Failing test:

{{{#!diff
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 2adfa51360..b9cc4d119c 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -19,6 +19,7 @@ from django.db import (
 from django.db.backends.base.base import BaseDatabaseWrapper
 from django.db.backends.signals import connection_created
 from django.db.backends.utils import CursorWrapper
 from django.db.models.sql.constants import CURSOR
 from django.test import (
     TestCase,
@@ -74,7 +75,9 @@ class LastExecutedQueryTest(TestCase):
         query has been run.
         """"""
         with connection.cursor() as cursor:
-            connection.ops.last_executed_query(cursor, """", ())
+            if connection.vendor == ""oracle"":
+                cursor.statement = None
+            connection.ops.last_executed_query(cursor, ""SELECT %s;"", (1,))
 
     def test_debug_sql(self):
         list(Reporter.objects.filter(first_name=""test""))
}}}

The actual failure (where `cursor.statement` was None) happened via making this copy-paste mistake from the `as_sql()` method before it:
{{{#!diff
diff --git a/django/db/models/fields/json.py b/django/db/models/fields/json.py
index d59c3afd71..108e4d7b0d 100644
--- a/django/db/models/fields/json.py
+++ b/django/db/models/fields/json.py
@@ -252,7 +252,7 @@ class HasKeyLookup(PostgresOperatorLookup):
             # queries but it is assumed that it cannot be evaded because the
             # path is JSON serialized.
             sql_parts.append(template % (lhs_sql, rhs_json_path))
-            params.extend(lhs_params)
+            params.extend(list(lhs_params) + [rhs_json_path])
         return self._combine_sql_parts(sql_parts), tuple(params)
 
     def as_postgresql(self, compiler, connection):
}}}"	Bug	assigned	Testing framework	dev	Normal				Unreviewed	1	0	0	0	1	0
