From 92613b0f19fc657717f8968aee572577da422e34 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 30 Jan 2019 21:45:45 +0900 Subject: [PATCH 1/3] Add some garbage for Django 1.11 compatibility Django touched private area of this library. Removing unused variables broke Django. While Django 2.0 fixed it, Django 1.11 doesn't fix it because it is in security-only fix mode. So add unused variables for Django 1.11 compatibility. They will be removed in next minor release. Fix #303, #306 --- MySQLdb/connections.py | 8 ++++++++ MySQLdb/cursors.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index c7c4c14f..ca53626a 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -166,6 +166,14 @@ class object, used to create cursors (keyword only) self.encoders = dict([ (k, v) for k, v in conv.items() if type(k) is not int ]) + # XXX THIS IS GARBAGE: While this is just a garbage and undocumented, + # Django 1.11 depends on it. And they don't fix it because + # they are in security-only fix mode. + # So keep this garbage for now. This will be removed in 1.5. + # See PyMySQL/mysqlclient-python#306 + self.encoders[unicode] = unicode + self.encoders[bytes] = bytes + self._server_version = tuple([ numeric_part(n) for n in self.get_server_info().split('.')[:2] ]) self.encoding = 'ascii' # overridden in set_character_set() diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index b8c0d886..b7c5d750 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -63,6 +63,14 @@ def __init__(self, connection): self.rowcount = -1 self.arraysize = 1 self._executed = None + + # XXX THIS IS GARBAGE: While this is totally garbage and private, + # Django 1.11 depends on it. And they don't fix it because + # they are in security-only fix mode. + # So keep this garbage for now. This will be removed in 1.5. + # See PyMySQL/mysqlclient-python#303 + self._last_executed = None + self.lastrowid = None self.messages = [] self._result = None @@ -300,6 +308,7 @@ def _query(self, q): self._do_get_result(db) self._post_get_result() self._executed = q + self._last_executed = q # XXX THIS IS GARBAGE: See above. return self.rowcount def _fetch_row(self, size=1): From 66058f06a4ad95bbc47bc103371e14656c963a9b Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 30 Jan 2019 21:59:53 +0900 Subject: [PATCH 2/3] fix --- MySQLdb/connections.py | 1 - 1 file changed, 1 deletion(-) diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index ca53626a..61061c58 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -171,7 +171,6 @@ class object, used to create cursors (keyword only) # they are in security-only fix mode. # So keep this garbage for now. This will be removed in 1.5. # See PyMySQL/mysqlclient-python#306 - self.encoders[unicode] = unicode self.encoders[bytes] = bytes self._server_version = tuple([ numeric_part(n) for n in self.get_server_info().split('.')[:2] ]) From a17e27dfaee9c073865cb8c058d02361bfae4d0a Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 30 Jan 2019 22:19:19 +0900 Subject: [PATCH 3/3] Fix PY2 support --- MySQLdb/connections.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 61061c58..37b52d81 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -245,8 +245,11 @@ def literal(self, o): s = self.string_literal(o.encode(self.encoding)) elif isinstance(o, bytearray): s = self._bytes_literal(o) - elif not PY2 and isinstance(o, bytes): - s = self._bytes_literal(o) + elif isinstance(o, bytes): + if PY2: + s = self.string_literal(o) + else: + s = self._bytes_literal(o) elif isinstance(o, (tuple, list)): s = self._tuple_literal(o) else: