Fixed #30380 -- Handled bytes in MySQL backend for PyMySQL support.
This commit partly reverts efd8a82e26
.
This commit is contained in:
parent
12b7956fc3
commit
a41b09266d
|
@ -4,6 +4,7 @@ from django.conf import settings
|
||||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.duration import duration_microseconds
|
from django.utils.duration import duration_microseconds
|
||||||
|
from django.utils.encoding import force_str
|
||||||
|
|
||||||
|
|
||||||
class DatabaseOperations(BaseDatabaseOperations):
|
class DatabaseOperations(BaseDatabaseOperations):
|
||||||
|
@ -141,10 +142,8 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
# With MySQLdb, cursor objects have an (undocumented) "_executed"
|
# With MySQLdb, cursor objects have an (undocumented) "_executed"
|
||||||
# attribute where the exact query sent to the database is saved.
|
# attribute where the exact query sent to the database is saved.
|
||||||
# See MySQLdb/cursors.py in the source distribution.
|
# See MySQLdb/cursors.py in the source distribution.
|
||||||
query = getattr(cursor, '_executed', None)
|
# MySQLdb returns string, PyMySQL bytes.
|
||||||
if query is not None:
|
return force_str(getattr(cursor, '_last_executed', None), errors='replace')
|
||||||
query = query.decode(errors='replace')
|
|
||||||
return query
|
|
||||||
|
|
||||||
def no_limit_value(self):
|
def no_limit_value(self):
|
||||||
# 2**64 - 1, as recommended by the MySQL documentation
|
# 2**64 - 1, as recommended by the MySQL documentation
|
||||||
|
|
|
@ -31,8 +31,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||||
|
|
||||||
def quote_value(self, value):
|
def quote_value(self, value):
|
||||||
self.connection.ensure_connection()
|
self.connection.ensure_connection()
|
||||||
|
# MySQLdb escapes to string, PyMySQL to bytes.
|
||||||
quoted = self.connection.connection.escape(value, self.connection.connection.encoders)
|
quoted = self.connection.connection.escape(value, self.connection.connection.encoders)
|
||||||
if isinstance(value, str):
|
if isinstance(value, str) and isinstance(quoted, bytes):
|
||||||
quoted = quoted.decode()
|
quoted = quoted.decode()
|
||||||
return quoted
|
return quoted
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue