Fixed #31758 -- Removed unneeded BytesToCharFieldConversionMixin.

Bug was fixed in mysqlclient 1.3.13.
This commit is contained in:
Sergey Fedoseev 2020-07-03 00:26:01 +05:00 committed by GitHub
parent b142bd4a1b
commit 37389ae99e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 22 deletions

View File

@ -253,9 +253,6 @@ class BaseDatabaseFeatures:
# Does the backend support keyword parameters for cursor.callproc()? # Does the backend support keyword parameters for cursor.callproc()?
supports_callproc_kwargs = False 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? # What formats does the backend EXPLAIN syntax support?
supported_explain_formats = set() supported_explain_formats = set()

View File

@ -41,7 +41,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
SET V_I = P_I; SET V_I = P_I;
END; END;
""" """
db_functions_convert_bytes_to_str = True
# Neither MySQL nor MariaDB support partial indexes. # Neither MySQL nor MariaDB support partial indexes.
supports_partial_indexes = False supports_partial_indexes = False
supports_order_by_nulls_modifier = False supports_order_by_nulls_modifier = False

View File

@ -5,22 +5,6 @@ from django.db.models.functions import Coalesce
from django.db.models.lookups import Transform 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: class MySQLSHA2Mixin:
def as_mysql(self, compiler, connection, **extra_content): def as_mysql(self, compiler, connection, **extra_content):
return super().as_sql( return super().as_sql(
@ -172,7 +156,7 @@ class Lower(Transform):
lookup_name = 'lower' lookup_name = 'lower'
class LPad(BytesToCharFieldConversionMixin, Func): class LPad(Func):
function = 'LPAD' function = 'LPAD'
output_field = CharField() output_field = CharField()
@ -204,7 +188,7 @@ class Ord(Transform):
return super().as_sql(compiler, connection, function='UNICODE', **extra_context) return super().as_sql(compiler, connection, function='UNICODE', **extra_context)
class Repeat(BytesToCharFieldConversionMixin, Func): class Repeat(Func):
function = 'REPEAT' function = 'REPEAT'
output_field = CharField() output_field = CharField()