From 37389ae99eb17ee8e2db39545d0e13f5ab8f006a Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Fri, 3 Jul 2020 00:26:01 +0500 Subject: [PATCH] Fixed #31758 -- Removed unneeded BytesToCharFieldConversionMixin. Bug was fixed in mysqlclient 1.3.13. --- django/db/backends/base/features.py | 3 --- django/db/backends/mysql/features.py | 1 - django/db/models/functions/text.py | 20 ++------------------ 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py index 88064e66f2..e156c56bda 100644 --- a/django/db/backends/base/features.py +++ b/django/db/backends/base/features.py @@ -253,9 +253,6 @@ class BaseDatabaseFeatures: # Does the backend support keyword parameters for cursor.callproc()? supports_callproc_kwargs = False - # Convert CharField results from bytes to str in database functions. - db_functions_convert_bytes_to_str = False - # What formats does the backend EXPLAIN syntax support? supported_explain_formats = set() diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index b8aed23207..06a111a75b 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -41,7 +41,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): SET V_I = P_I; END; """ - db_functions_convert_bytes_to_str = True # Neither MySQL nor MariaDB support partial indexes. supports_partial_indexes = False supports_order_by_nulls_modifier = False diff --git a/django/db/models/functions/text.py b/django/db/models/functions/text.py index 7289d5fb97..4c52222ba1 100644 --- a/django/db/models/functions/text.py +++ b/django/db/models/functions/text.py @@ -5,22 +5,6 @@ from django.db.models.functions import Coalesce from django.db.models.lookups import Transform -class BytesToCharFieldConversionMixin: - """ - Convert CharField results from bytes to str. - - MySQL returns long data types (bytes) instead of chars when it can't - determine the length of the result string. For example: - LPAD(column1, CHAR_LENGTH(column2), ' ') - returns the LONGTEXT (bytes) instead of VARCHAR. - """ - def convert_value(self, value, expression, connection): - if connection.features.db_functions_convert_bytes_to_str: - if self.output_field.get_internal_type() == 'CharField' and isinstance(value, bytes): - return value.decode() - return super().convert_value(value, expression, connection) - - class MySQLSHA2Mixin: def as_mysql(self, compiler, connection, **extra_content): return super().as_sql( @@ -172,7 +156,7 @@ class Lower(Transform): lookup_name = 'lower' -class LPad(BytesToCharFieldConversionMixin, Func): +class LPad(Func): function = 'LPAD' output_field = CharField() @@ -204,7 +188,7 @@ class Ord(Transform): return super().as_sql(compiler, connection, function='UNICODE', **extra_context) -class Repeat(BytesToCharFieldConversionMixin, Func): +class Repeat(Func): function = 'REPEAT' output_field = CharField()