From b19365f92c95d34dae9e0edbe8349481a87aaa57 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 2 Feb 2024 16:59:28 +0900 Subject: [PATCH 1/3] Support error packet without sqlstate --- pymysql/connections.py | 2 -- pymysql/err.py | 10 +++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index dc121e1bb..3a04ddd68 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -765,8 +765,6 @@ def _read_packet(self, packet_type=MysqlPacket): dump_packet(recv_data) buff += recv_data # https://dev.mysql.com/doc/internals/en/sending-more-than-16mbyte.html - if bytes_to_read == 0xFFFFFF: - continue if bytes_to_read < MAX_PACKET_LEN: break diff --git a/pymysql/err.py b/pymysql/err.py index 3da5b166f..5ac6003a5 100644 --- a/pymysql/err.py +++ b/pymysql/err.py @@ -136,7 +136,15 @@ def _map_error(exc, *errors): def raise_mysql_exception(data): errno = struct.unpack(" Date: Fri, 2 Feb 2024 17:01:52 +0900 Subject: [PATCH 2/3] fix lint error --- pymysql/err.py | 1 - pyproject.toml | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pymysql/err.py b/pymysql/err.py index 5ac6003a5..dac65d3be 100644 --- a/pymysql/err.py +++ b/pymysql/err.py @@ -136,7 +136,6 @@ def _map_error(exc, *errors): def raise_mysql_exception(data): errno = struct.unpack(" Date: Fri, 2 Feb 2024 17:12:25 +0900 Subject: [PATCH 3/3] add test --- pymysql/tests/test_err.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pymysql/tests/test_err.py b/pymysql/tests/test_err.py index 6b54c6d04..6eb0f987d 100644 --- a/pymysql/tests/test_err.py +++ b/pymysql/tests/test_err.py @@ -1,14 +1,16 @@ -import unittest - +import pytest from pymysql import err -__all__ = ["TestRaiseException"] - +def test_raise_mysql_exception(): + data = b"\xff\x15\x04#28000Access denied" + with pytest.raises(err.OperationalError) as cm: + err.raise_mysql_exception(data) + assert cm.type == err.OperationalError + assert cm.value.args == (1045, "Access denied") -class TestRaiseException(unittest.TestCase): - def test_raise_mysql_exception(self): - data = b"\xff\x15\x04#28000Access denied" - with self.assertRaises(err.OperationalError) as cm: - err.raise_mysql_exception(data) - self.assertEqual(cm.exception.args, (1045, "Access denied")) + data = b"\xff\x10\x04Too many connections" + with pytest.raises(err.OperationalError) as cm: + err.raise_mysql_exception(data) + assert cm.type == err.OperationalError + assert cm.value.args == (1040, "Too many connections")