Skip to content

Fix SSCursor raising query timeout error on wrong query on MySQL DB #1035

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

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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

Release date: TBD

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


## v1.0.3

Release date: TBD

* Dropped support of end of life MySQL version 5.6
* Dropped support of end of life MariaDB versions below 10.3
* Dropped support of end of life Python version 3.6
* Exposed `Cursor.warning_count` to check for warnings without additional query (#1056)


## v1.0.2
Expand Down
15 changes: 14 additions & 1 deletion pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,20 @@ def _finish_unbuffered_query(self):
# in fact, no way to stop MySQL from sending all the data after
# executing a query, so we just spin, and wait for an EOF packet.
while self.unbuffered_active:
packet = self.connection._read_packet()
try:
packet = self.connection._read_packet()
except err.OperationalError as e:
if e.args[0] in (
ER.QUERY_TIMEOUT,
ER.STATEMENT_TIMEOUT,
):
# if the query timed out we can simply ignore this error
self.unbuffered_active = False
self.connection = None
return

raise

if self._check_packet_is_eof(packet):
self.unbuffered_active = False
self.connection = None # release reference to kill cyclic reference.
Expand Down