From 5a2fdfb38a22950d0d6cbd5c3763ea48d89d03cb Mon Sep 17 00:00:00 2001 From: dikoufu Date: Fri, 8 Jan 2016 23:14:46 -0800 Subject: [PATCH 1/4] To fix the bug caused by DictCursor mode. When cursorclass is DictCursor in MYSQL_SETTINGS ,will appear an Error: TypeError: unhashable type. --- pymysqlreplication/binlogstream.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index e6748451..217a82b7 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -113,7 +113,10 @@ def __checksum_enabled(self): if result is None: return False - var, value = result[:2] + if "DictCursor" in repr(self.__connection_settings["cursorclass"]): + value = result["Value"] + else: + var, value = result[:2] if value == 'NONE': return False return True @@ -140,7 +143,10 @@ def __connect_to_stream(self): if self.log_file is None or self.log_pos is None: cur = self._stream_connection.cursor() cur.execute("SHOW MASTER STATUS") - self.log_file, self.log_pos = cur.fetchone()[:2] + if "DictCursor" in repr(self.__connection_settings["cursorclass"]): + self.log_file, self.log_pos = data["File"], data["Position"] + else: + self.log_file, self.log_pos = cur.fetchone()[:2] cur.close() prelude = struct.pack(' Date: Sat, 9 Jan 2016 00:11:19 -0800 Subject: [PATCH 2/4] To fix the bug caused by DictCursor mode. When cursorclass is DictCursor in MYSQL_SETTINGS ,will appear an Error: TypeError: unhashable type. --- pymysqlreplication/binlogstream.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index 217a82b7..c07e9c68 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -113,7 +113,8 @@ def __checksum_enabled(self): if result is None: return False - if "DictCursor" in repr(self.__connection_settings["cursorclass"]): + if ("cursorclass" in self.__connection_settings) and \ + ("DictCursor" in repr(self.__connection_settings["cursorclass"])): value = result["Value"] else: var, value = result[:2] @@ -143,7 +144,8 @@ def __connect_to_stream(self): if self.log_file is None or self.log_pos is None: cur = self._stream_connection.cursor() cur.execute("SHOW MASTER STATUS") - if "DictCursor" in repr(self.__connection_settings["cursorclass"]): + if ("cursorclass" in self.__connection_settings) and \ + ("DictCursor" in repr(self.__connection_settings["cursorclass"])): self.log_file, self.log_pos = data["File"], data["Position"] else: self.log_file, self.log_pos = cur.fetchone()[:2] From d173f9e79e9fd18ba6817a1d85e80663563e039b Mon Sep 17 00:00:00 2001 From: dikoufu Date: Sun, 10 Jan 2016 17:37:32 -0800 Subject: [PATCH 3/4] change code for using a more simple method --- pymysqlreplication/binlogstream.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index c07e9c68..48bd10fb 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -113,8 +113,7 @@ def __checksum_enabled(self): if result is None: return False - if ("cursorclass" in self.__connection_settings) and \ - ("DictCursor" in repr(self.__connection_settings["cursorclass"])): + if type(result) == type({}): value = result["Value"] else: var, value = result[:2] @@ -144,8 +143,7 @@ def __connect_to_stream(self): if self.log_file is None or self.log_pos is None: cur = self._stream_connection.cursor() cur.execute("SHOW MASTER STATUS") - if ("cursorclass" in self.__connection_settings) and \ - ("DictCursor" in repr(self.__connection_settings["cursorclass"])): + if type(data) == type({}): self.log_file, self.log_pos = data["File"], data["Position"] else: self.log_file, self.log_pos = cur.fetchone()[:2] From 20655790ddbc2a9936e3d5bb4f5d917bb640c673 Mon Sep 17 00:00:00 2001 From: dikoufu Date: Sun, 10 Jan 2016 17:44:04 -0800 Subject: [PATCH 4/4] change code for using a more simple method --- pymysqlreplication/binlogstream.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index 48bd10fb..658a4381 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -143,6 +143,7 @@ def __connect_to_stream(self): if self.log_file is None or self.log_pos is None: cur = self._stream_connection.cursor() cur.execute("SHOW MASTER STATUS") + data = cur.fetchone() if type(data) == type({}): self.log_file, self.log_pos = data["File"], data["Position"] else: