Ticket #18461: 18461-1.diff

File 18461-1.diff, 2.2 KB (added by Claude Paroz, 12 years ago)

Decode returned value from last executed query

  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index 9de3287..f381d48 100644
    a b class DatabaseOperations(BaseDatabaseOperations):  
    238238        # With MySQLdb, cursor objects have an (undocumented) "_last_executed"
    239239        # attribute where the exact query sent to the database is saved.
    240240        # See MySQLdb/cursors.py in the source distribution.
    241         return cursor._last_executed
     241        return cursor._last_executed.decode('utf-8')
    242242
    243243    def no_limit_value(self):
    244244        # 2**64 - 1, as recommended by the MySQL documentation
  • django/db/backends/postgresql_psycopg2/operations.py

    diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py
    index 46b464b..88a413b 100644
    a b class DatabaseOperations(BaseDatabaseOperations):  
    193193    def last_executed_query(self, cursor, sql, params):
    194194        # http://initd.org/psycopg/docs/cursor.html#cursor.query
    195195        # The query attribute is a Psycopg extension to the DB API 2.0.
    196         return cursor.query
     196        return cursor.query.decode('utf-8')
    197197
    198198    def return_insert_id(self):
    199199        return "RETURNING %s", ()
  • tests/regressiontests/logging_tests/tests.py

    diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py
    index 4ae3c1b..d443101 100644
    a b  
     1# -*- encoding: utf-8 -*-
    12from __future__ import unicode_literals
    23
    34import copy
    class AdminEmailHandlerTest(TestCase):  
    252253
    253254        self.assertEqual(len(mail.outbox), 1)
    254255        self.assertEqual(mail.outbox[0].subject, expected_subject)
     256
     257class RequestLoggingTest(TestCase):
     258    @override_settings(DEBUG=True)
     259    def test_sql_logging(self):
     260        """
     261        Test that sql logging of last executed query doesn't produce decoding
     262        error with Unicode caracters (#18461)
     263        """
     264        from django.contrib.auth.models import User
     265        q = list(User.objects.filter(last_name='й'))
Back to Top