From 7a301a2c45aa42c022298944c2a7786a05421e9d Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 9 Sep 2014 22:18:39 +0900 Subject: [PATCH 1/2] Exception raised from _mysql should be reraise as is. --- tests/test_MySQLdb_capabilities.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_MySQLdb_capabilities.py b/tests/test_MySQLdb_capabilities.py index c45353fd..6f46ea99 100644 --- a/tests/test_MySQLdb_capabilities.py +++ b/tests/test_MySQLdb_capabilities.py @@ -92,7 +92,16 @@ def test_bug_3514287(self): def test_ping(self): self.connection.ping() - + + def test_reraise_exception(self): + c = self.cursor + try: + c.execute("SELECT x FROM not_existing_table") + except MySQLdb.ProgrammingError as e: + self.assertEqual(e.args[0], 1146) + return + self.fail("Should raise ProgrammingError") + if __name__ == '__main__': if test_MySQLdb.leak_test: From 739bc9325d44d356a678a6fd5632150052a490cf Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 9 Sep 2014 22:19:56 +0900 Subject: [PATCH 2/2] fix. --- MySQLdb/connections.py | 2 ++ MySQLdb/cursors.py | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 8d5c2d8a..828c364d 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -34,6 +34,8 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue): connection.messages.append(error) del cursor del connection + if isinstance(errorvalue, BaseException): + raise errorvalue if errorclass is not None: raise errorclass(errorvalue) else: diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 1ce6629f..a781695f 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -214,8 +214,7 @@ def execute(self, query, args=None): except (SystemExit, KeyboardInterrupt): raise except: - exc, value, tb = sys.exc_info() - del tb + exc, value = sys.exc_info()[:2] self.messages.append((exc, value)) self.errorhandler(self, exc, value) self._executed = query @@ -273,8 +272,7 @@ def executemany(self, query, args): except (SystemExit, KeyboardInterrupt): raise except: - exc, value, tb = sys.exc_info() - del tb + exc, value = sys.exc_info()[:2] self.errorhandler(self, exc, value) qs = '\n'.join([query[:p], ',\n'.join(q), query[e:]]) if not PY2: