Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception raised from _mysql should be reraise as is. #6

Merged
merged 2 commits into from
Sep 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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