Skip to content

Commit

Permalink
Merge pull request #6 from PyMySQL/fix-nested-exception
Browse files Browse the repository at this point in the history
Exception raised from _mysql should be reraise as is.
  • Loading branch information
methane committed Sep 9, 2014
2 parents 19a7344 + 739bc93 commit e6b0fc3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions MySQLdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions MySQLdb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_MySQLdb_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e6b0fc3

Please sign in to comment.