8000 Fix SSCursor raising query timeout error on wrong query on MySQL DB by Nothing4You · Pull Request #1035 · PyMySQL/PyMySQL · GitHub
[go: up one dir, main page]

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 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' into fix-sscursor-raising-error-from-previous-query
  • Loading branch information
methane authored May 23, 2023
commit 77eeff950dad203b45191b608d2fbccad29e1cdd
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
* Fixed SSCursor raising OperationalError for query timeouts on wrong statement #1032


## v1.0.2
Expand Down
2 changes: 0 additions & 2 deletions pymysql/constants/ER.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,6 @@

# MariaDB only
STATEMENT_TIMEOUT = 1969

QUERY_TIMEOUT = 3024

# https://github.com/PyMySQL/PyMySQL/issues/607
CONSTRAINT_FAILED = 4025
52 changes: 34 additions & 18 deletions pymysql/tests/test_SSCursor.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import pytest

import pytest

try:
from pymysql.tests import base
import pymysql.cursors
from pymysql.constants import CLIENT
import pymysql.constants.ER
except Exception:
# For local testing from top-level directory, without installing
sys.path.append("../pymysql")
from pymysql.tests import base
import pymysql.cursors
from pymysql.constants import CLIENT
import pymysql.constants.ER
from pymysql.tests import base
import pymysql.cursors
from pymysql.constants import CLIENT, ER


class TestSSCursor(base.PyMySQLTestCase):
Expand Down Expand Up @@ -204,16 +193,43 @@ def test_execution_time_limit(self):
if db_type == "mysql":
# this constant was only introduced in MySQL 5.7, not sure
# what was returned before, may have been ER_QUERY_INTERRUPTED
self.assertEqual(cm.value.args[0], pymysql.constants.ER.QUERY_TIMEOUT)
self.assertEqual(cm.value.args[0], ER.QUERY_TIMEOUT)
else:
self.assertEqual(
cm.value.args[0], pymysql.constants.ER.STATEMENT_TIMEOUT
)
self.assertEqual(cm.value.args[0], ER.STATEMENT_TIMEOUT)

# connection should still be fine at this point
cur.execute("SELECT 1")
self.assertEqual(cur.fetchone(), (1,))

def test_warnings(self):
con = self.connect()
cur = con.cursor(pymysql.cursors.SSCursor)
cur.execute("DROP TABLE IF EXISTS `no_exists_table`")
self.assertEqual(cur.warning_count, 1)

cur.execute("SHOW WARNINGS")
w = cur.fetchone()
self.assertEqual(w[1], ER.BAD_TABLE_ERROR)
self.assertIn(
"no_exists_table",
w[2],
)

# ensure unbuffered result is finished
self.assertIsNone(cur.fetchone())

cur.execute("SELECT 1")
self.assertEqual(cur.fetchone(), (1,))
self.assertIsNone(cur.fetchone())

self.assertEqual(cur.warning_count, 0)

cur.execute("SELECT CAST('abc' AS SIGNED)")
# this ensures fully retrieving the unbuffered result
rows = cur.fetchmany(2)
self.assertEqual(len(rows), 1)
self.assertEqual(cur.warning_count, 1)


__all__ = ["TestSSCursor"]

Expand Down
23 changes: 19 additions & 4 deletions pymysql/tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,27 @@ def test_execution_time_limit(self):
if db_type == "mysql":
# this constant was only introduced in MySQL 5.7, not sure
# what was returned before, may have been ER_QUERY_INTERRUPTED
self.assertEqual(cm.value.args[0], pymysql.constants.ER.QUERY_TIMEOUT)
self.assertEqual(cm.value.args[0], ER.QUERY_TIMEOUT)
else:
self.assertEqual(
cm.value.args[0], pymysql.constants.ER.STATEMENT_TIMEOUT
)
self.assertEqual(cm.value.args[0], ER.STATEMENT_TIMEOUT)

# connection should still be fine at this point
cur.execute("SELECT 1")
self.assertEqual(cur.fetchone(), (1,))

def test_warnings(self):
con = self.connect()
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS `no_exists_table`")
self.assertEqual(cur.warning_count, 1)

cur.execute("SHOW WARNINGS")
w = cur.fetchone()
self.assertEqual(w[1], ER.BAD_TABLE_ERROR)
self.assertIn(
"no_exists_table",
w[2],
)

cur.execute("SELECT 1")
self.assertEqual(cur.warning_count, 0)
You are viewing a condensed version of this merge commit. You can view the full changes here.
0