Skip to content

Commit 3cd76d7

Browse files
authored
Fix SSCursor raising query timeout error on wrong query on MySQL DB (#1035)
Fixes #1032 (comment)
1 parent 2ee4f70 commit 3cd76d7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
Release date: TBD
66

7+
* Fixed SSCursor raising OperationalError for query timeouts on wrong statement (#1032)
78
* Exposed `Cursor.warning_count` to check for warnings without additional query (#1056)
89

10+
911
## v1.0.3
1012

1113
Release date: TBD

pymysql/connections.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,20 @@ def _finish_unbuffered_query(self):
12621262
# in fact, no way to stop MySQL from sending all the data after
12631263
# executing a query, so we just spin, and wait for an EOF packet.
12641264
while self.unbuffered_active:
1265-
packet = self.connection._read_packet()
1265+
try:
1266+
packet = self.connection._read_packet()
1267+
except err.OperationalError as e:
1268+
if e.args[0] in (
1269+
ER.QUERY_TIMEOUT,
1270+
ER.STATEMENT_TIMEOUT,
1271+
):
1272+
# if the query timed out we can simply ignore this error
1273+
self.unbuffered_active = False
1274+
self.connection = None
1275+
return
1276+
1277+
raise
1278+
12661279
if self._check_packet_is_eof(packet):
12671280
self.unbuffered_active = False
12681281
self.connection = None # release reference to kill cyclic reference.

0 commit comments

Comments
 (0)