From ba8ab722ac27991e61d935bcd4342fe10a7fba58 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 31 Jul 2019 20:59:40 +0900 Subject: [PATCH 1/2] fix Cursor.executemany created many circular references --- MySQLdb/cursors.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 82eb64e7..6930f174 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -110,14 +110,17 @@ def ensure_bytes(x): return x if isinstance(args, (tuple, list)): - return tuple(literal(ensure_bytes(arg)) for arg in args) + ret = tuple(literal(ensure_bytes(arg)) for arg in args) elif isinstance(args, dict): - return {ensure_bytes(key): literal(ensure_bytes(val)) - for (key, val) in args.items()} + ret = {ensure_bytes(key): literal(ensure_bytes(val)) + for (key, val) in args.items()} else: # If it's not a dictionary let's try escaping it anyways. # Worst case it will throw a Value error - return literal(ensure_bytes(args)) + ret = literal(ensure_bytes(args)) + + del ensure_bytes # break circular reference + return ret def _check_executed(self): if not self._executed: From 5f6ec93134232c77082496613dddb5bb85116191 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 31 Jul 2019 21:50:15 +0900 Subject: [PATCH 2/2] fix Py2 support --- MySQLdb/cursors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 6930f174..ee834e45 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -119,7 +119,7 @@ def ensure_bytes(x): # Worst case it will throw a Value error ret = literal(ensure_bytes(args)) - del ensure_bytes # break circular reference + ensure_bytes = None # break circular reference return ret def _check_executed(self):