Ticket #17158: 17158.patch

File 17158.patch, 3.1 KB (added by aaugustin, 2 years ago)
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 78dbbc6..7dc5456 100644
    a b class BaseDatabaseOperations(object): 
    614614        # Convert params to contain Unicode values.
    615615        to_unicode = lambda s: force_text(s, strings_only=True, errors='replace')
    616616        if isinstance(params, (list, tuple)):
    617             u_params = tuple([to_unicode(val) for val in params])
     617            u_params = tuple(to_unicode(val) for val in params)
    618618        else:
    619             u_params = dict([(to_unicode(k), to_unicode(v)) for k, v in params.items()])
     619            u_params = dict((to_unicode(k), to_unicode(v)) for k, v in params.items())
    620620
    621         return force_text(sql) % u_params
     621        return six.text_type("QUERY = %r - PARAMS = %r") % (sql, u_params)
    622622
    623623    def last_insert_id(self, cursor, table_name, pk_name):
    624624        """
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    index b293847..313fdc8 100644
    a b from django.db.models import fields, Sum, Avg, Variance, StdDev 
    1616from django.db.utils import ConnectionHandler, DatabaseError, load_backend
    1717from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
    1818    TransactionTestCase)
    19 from django.test.utils import override_settings
     19from django.test.utils import override_settings, str_prefix
    2020from django.utils import six
    2121from django.utils.six.moves import xrange
    2222from django.utils import unittest
    class DateQuotingTest(TestCase): 
    160160        self.assertEqual(len(classes), 1)
    161161
    162162
     163@override_settings(DEBUG=True)
    163164class LastExecutedQueryTest(TestCase):
    164     @override_settings(DEBUG=True)
     165
    165166    def test_debug_sql(self):
    166167        list(models.Tag.objects.filter(name="test"))
    167168        sql = connection.queries[-1]['sql'].lower()
    168         self.assertTrue(sql.startswith("select"))
     169        self.assertIn("select", sql)
    169170        self.assertIn(models.Tag._meta.db_table, sql)
    170171
    171172    def test_query_encoding(self):
    172173        """
    173174        Test that last_executed_query() returns an Unicode string
    174175        """
    175         tags = models.Tag.objects.extra(select={'föö':1})
     176        tags = models.Tag.objects.extra(select={'föö': 1})
    176177        sql, params = tags.query.sql_with_params()
    177178        cursor = tags.query.get_compiler('default').execute_sql(None)
    178179        last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
    179180        self.assertTrue(isinstance(last_sql, six.text_type))
    180181
     182    @unittest.skipUnless(connection.vendor == 'sqlite',
     183                         "This test is specific to SQLite.")
     184    def test_no_interpolation_on_sqlite(self):
     185        # Regression for #17158
     186        # This shouldn't raise an exception
     187        query = "SELECT strftime('%Y', 'now');"
     188        connection.cursor().execute(query)
     189        self.assertEqual(connection.queries[-1]['sql'],
     190            str_prefix("QUERY = %(_)s\"SELECT strftime('%%Y', 'now');\" - PARAMS = ()"))
    181191
    182192class ParameterHandlingTest(TestCase):
    183193    def test_bad_parameter_count(self):
Back to Top