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()