Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e6b0fc3

Browse filesBrowse files
committed
Merge pull request PyMySQL#6 from PyMySQL/fix-nested-exception
Exception raised from _mysql should be reraise as is.
2 parents 19a7344 + 739bc93 commit e6b0fc3
Copy full SHA for e6b0fc3

File tree

Expand file treeCollapse file tree

3 files changed

+14
-5
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-5
lines changed

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
3434
connection.messages.append(error)
3535
del cursor
3636
del connection
37+
if isinstance(errorvalue, BaseException):
38+
raise errorvalue
3739
if errorclass is not None:
3840
raise errorclass(errorvalue)
3941
else:

‎MySQLdb/cursors.py

Copy file name to clipboardExpand all lines: MySQLdb/cursors.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ def execute(self, query, args=None):
214214
except (SystemExit, KeyboardInterrupt):
215215
raise
216216
except:
217-
exc, value, tb = sys.exc_info()
218-
del tb
217+
exc, value = sys.exc_info()[:2]
219218
self.messages.append((exc, value))
220219
self.errorhandler(self, exc, value)
221220
self._executed = query
@@ -273,8 +272,7 @@ def executemany(self, query, args):
273272
except (SystemExit, KeyboardInterrupt):
274273
raise
275274
except:
276-
exc, value, tb = sys.exc_info()
277-
del tb
275+
exc, value = sys.exc_info()[:2]
278276
self.errorhandler(self, exc, value)
279277
qs = '\n'.join([query[:p], ',\n'.join(q), query[e:]])
280278
if not PY2:

‎tests/test_MySQLdb_capabilities.py

Copy file name to clipboardExpand all lines: tests/test_MySQLdb_capabilities.py
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ def test_bug_3514287(self):
9292

9393
def test_ping(self):
9494
self.connection.ping()
95-
95+
96+
def test_reraise_exception(self):
97+
c = self.cursor
98+
try:
99+
c.execute("SELECT x FROM not_existing_table")
100+
except MySQLdb.ProgrammingError as e:
101+
self.assertEqual(e.args[0], 1146)
102+
return
103+
self.fail("Should raise ProgrammingError")
104+
96105

97106
if __name__ == '__main__':
98107
if test_MySQLdb.leak_test:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.