#36111: --debug-sql fails on Oracle if a query with params fails to execute and
no
prior query has either
---------------------------------------------+-----------------------------
Reporter: Jacob Walls | Owner: Jacob Walls
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
---------------------------------------------+-----------------------------
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;", (Value(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 import Value
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;",
(Value(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):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36111>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/010701947adcc9ab-dda3ae84-2f62-4dff-8f9d-7793e2e683aa-000000%40eu-central-1.amazonses.com.