Opened 5 hours ago
Last modified 5 hours ago
#36111 assigned Bug
--debug-sql fails on Oracle if a query with params fails to execute and no prior query has either
Reported by: | Jacob Walls | Owned by: | Jacob Walls |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
Noticed while working on ticket:35972 that an Oracle failure I wanted to debug with --debug-sql
failed like:
====================================================================== 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:
-
tests/backends/tests.py
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 2adfa51360..b9cc4d119c 100644
a b from django.db import ( (this hunk was shorter than expected) 19 19 from django.db.backends.base.base import BaseDatabaseWrapper 20 20 from django.db.backends.signals import connection_created 21 21 from django.db.backends.utils import CursorWrapper 22 22 from django.db.models.sql.constants import CURSOR 23 23 from django.test import ( 24 24 TestCase, … … class LastExecutedQueryTest(TestCase): 74 75 query has been run. 75 76 """ 76 77 with connection.cursor() as cursor: 77 connection.ops.last_executed_query(cursor, "", ()) 78 if connection.vendor == "oracle": 79 cursor.statement = None 80 connection.ops.last_executed_query(cursor, "SELECT %s;", (1,)) 78 81 79 82 def test_debug_sql(self): 80 83 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:
-
django/db/models/fields/json.py
diff --git a/django/db/models/fields/json.py b/django/db/models/fields/json.py index d59c3afd71..108e4d7b0d 100644
a b class HasKeyLookup(PostgresOperatorLookup): 252 252 # queries but it is assumed that it cannot be evaded because the 253 253 # path is JSON serialized. 254 254 sql_parts.append(template % (lhs_sql, rhs_json_path)) 255 params.extend(l hs_params)255 params.extend(list(lhs_params) + [rhs_json_path]) 256 256 return self._combine_sql_parts(sql_parts), tuple(params) 257 257 258 258 def as_postgresql(self, compiler, connection):
Change History (2)
comment:1 by , 5 hours ago
Has patch: | set |
---|
comment:2 by , 5 hours ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
PR