Opened 11 hours ago

Last modified 11 hours ago

#36111 assigned Bug

--debug-sql fails on Oracle if a query with params fails to execute and no prior query has either — at Initial Version

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

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;", (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:

  • 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 (  
    1919from django.db.backends.base.base import BaseDatabaseWrapper
    2020from django.db.backends.signals import connection_created
    2121from django.db.backends.utils import CursorWrapper
     22from django.db.models import Value
    2223from django.db.models.sql.constants import CURSOR
    2324from django.test import (
    2425    TestCase,
    class LastExecutedQueryTest(TestCase):  
    7475        query has been run.
    7576        """
    7677        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;", (Value(1),))
    7881
    7982    def test_debug_sql(self):
    8083        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):  
    252252            # queries but it is assumed that it cannot be evaded because the
    253253            # path is JSON serialized.
    254254            sql_parts.append(template % (lhs_sql, rhs_json_path))
    255             params.extend(lhs_params)
     255            params.extend(list(lhs_params) + [rhs_json_path])
    256256        return self._combine_sql_parts(sql_parts), tuple(params)
    257257
    258258    def as_postgresql(self, compiler, connection):

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top