diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2018-10-03 15:14:03 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2018-10-03 15:14:03 +0200 |
| commit | 54eedddb5084fb572516ad4d7266e13e290c3c8d (patch) | |
| tree | 4ed0ff381287a88f6884a21892f860de1eb58858 | |
| parent | f3f31b0fc26f772b198c9683a427f2f7fe208c37 (diff) | |
Revert "[2.1.x] Refs #27795 -- Removed force_bytes() usage in MySQL backend."
This reverts commit a47dd99cc6883fe3e35895e8c5d4bb53996bd184.
| -rw-r--r-- | django/db/backends/mysql/operations.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py index e3092f0c17..31f92ac5cd 100644 --- a/django/db/backends/mysql/operations.py +++ b/django/db/backends/mysql/operations.py @@ -4,6 +4,7 @@ from django.conf import settings from django.db.backends.base.operations import BaseDatabaseOperations from django.utils import timezone from django.utils.duration import duration_microseconds +from django.utils.encoding import force_text class DatabaseOperations(BaseDatabaseOperations): @@ -134,10 +135,7 @@ class DatabaseOperations(BaseDatabaseOperations): # With MySQLdb, cursor objects have an (undocumented) "_last_executed" # attribute where the exact query sent to the database is saved. # See MySQLdb/cursors.py in the source distribution. - query = getattr(cursor, '_last_executed', None) - if query is not None: - query = query.decode(errors='replace') - return query + return force_text(getattr(cursor, '_last_executed', None), errors='replace') def no_limit_value(self): # 2**64 - 1, as recommended by the MySQL documentation @@ -228,7 +226,9 @@ class DatabaseOperations(BaseDatabaseOperations): def get_db_converters(self, expression): converters = super().get_db_converters(expression) internal_type = expression.output_field.get_internal_type() - if internal_type in ['BooleanField', 'NullBooleanField']: + if internal_type == 'TextField': + converters.append(self.convert_textfield_value) + elif internal_type in ['BooleanField', 'NullBooleanField']: converters.append(self.convert_booleanfield_value) elif internal_type == 'DateTimeField': if settings.USE_TZ: @@ -237,6 +237,11 @@ class DatabaseOperations(BaseDatabaseOperations): converters.append(self.convert_uuidfield_value) return converters + def convert_textfield_value(self, value, expression, connection): + if value is not None: + value = force_text(value) + return value + def convert_booleanfield_value(self, value, expression, connection): if value in (0, 1): value = bool(value) |
