mysqlclient 2.3.1__tar.gz → 2.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/HISTORY.rst +19 -0
  2. {mysqlclient-2.3.1/src/mysqlclient.egg-info → mysqlclient-2.3.2}/PKG-INFO +1 -1
  3. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/_mysql.c +32 -8
  4. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/connections.py +4 -4
  5. mysqlclient-2.3.2/src/MySQLdb/release.py +3 -0
  6. {mysqlclient-2.3.1 → mysqlclient-2.3.2/src/mysqlclient.egg-info}/PKG-INFO +1 -1
  7. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test__mysql.py +11 -0
  8. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_connection.py +103 -5
  9. mysqlclient-2.3.1/src/MySQLdb/release.py +0 -3
  10. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/LICENSE +0 -0
  11. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/MANIFEST.in +0 -0
  12. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/README.md +0 -0
  13. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/doc/FAQ.rst +0 -0
  14. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/doc/MySQLdb.constants.rst +0 -0
  15. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/doc/MySQLdb.rst +0 -0
  16. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/doc/conf.py +0 -0
  17. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/doc/index.rst +0 -0
  18. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/doc/user_guide.rst +0 -0
  19. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/pyproject.toml +0 -0
  20. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/setup.cfg +0 -0
  21. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/setup.py +0 -0
  22. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/site.cfg +0 -0
  23. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/__init__.py +0 -0
  24. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/_exceptions.py +0 -0
  25. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/constants/CLIENT.py +0 -0
  26. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/constants/CR.py +0 -0
  27. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/constants/ER.py +0 -0
  28. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/constants/FIELD_TYPE.py +0 -0
  29. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/constants/FLAG.py +0 -0
  30. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/constants/__init__.py +0 -0
  31. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/converters.py +0 -0
  32. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/cursors.py +0 -0
  33. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/MySQLdb/times.py +0 -0
  34. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/mysqlclient.egg-info/SOURCES.txt +0 -0
  35. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/mysqlclient.egg-info/dependency_links.txt +0 -0
  36. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/src/mysqlclient.egg-info/top_level.txt +0 -0
  37. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/capabilities.py +0 -0
  38. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/configdb.py +0 -0
  39. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/dbapi20.py +0 -0
  40. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_MySQLdb_capabilities.py +0 -0
  41. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_MySQLdb_dbapi20.py +0 -0
  42. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_MySQLdb_nonstandard.py +0 -0
  43. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_MySQLdb_times.py +0 -0
  44. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_cursor.py +0 -0
  45. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_errors.py +0 -0
  46. {mysqlclient-2.3.1 → mysqlclient-2.3.2}/tests/test_sqlalchemy.py +0 -0
@@ -1,3 +1,22 @@
1
+ ======================
2
+ What's new in 2.3.2
3
+ ======================
4
+
5
+ Release: 2026-11-18
6
+
7
+ * Restore the use of the base type's literal conversion for subclasses of
8
+ ``str``, ``bytes``, and ``bytearray``. This fixes a regression in 2.3.1 where string-valued
9
+ ``enum.Enum`` members were serialized using their enum names instead of their
10
+ string values. (#814)
11
+
12
+ * Avoid a spurious ``ProgrammingError`` when another thread drops the last
13
+ reference to a buffered result while the connection is in use. (#815)
14
+
15
+ * Escape the contents of ``bytearray`` query parameters the same way as
16
+ ``bytes``. Previously, passing ``bytearray(b'ab')`` sent the Python string
17
+ representation to the server. This also applies to subclasses. (#817)
18
+
19
+
1
20
  ======================
2
21
  What's new in 2.3.1
3
22
  ======================
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mysqlclient
3
- Version: 2.3.1
3
+ Version: 2.3.2
4
4
  Summary: Python interface to MySQL
5
5
  Author-email: Inada Naoki <songofacandy@gmail.com>
6
6
  License-Expression: GPL-2.0-or-later
@@ -327,8 +327,22 @@ _mysql_ResultObject_Initialize(
327
327
  &_mysql_ConnectionObject_Type, &conn, &use, &conv))
328
328
  return -1;
329
329
 
330
- self->conn = (PyObject *) conn;
331
- Py_INCREF(conn);
330
+ /* A result keeps its original connection and buffering mode until deallocation. */
331
+ bool already_initialized;
332
+ #ifdef Py_GIL_DISABLED
333
+ Py_BEGIN_CRITICAL_SECTION(self);
334
+ #endif
335
+ already_initialized = self->conn != NULL;
336
+ if (!already_initialized) {
337
+ self->conn = Py_NewRef(conn);
338
+ }
339
+ #ifdef Py_GIL_DISABLED
340
+ Py_END_CRITICAL_SECTION();
341
+ #endif
342
+ if (already_initialized) {
343
+ PyErr_SetString(_mysql_ProgrammingError, "Result is already initialized");
344
+ return -1;
345
+ }
332
346
  self->use = use;
333
347
  if (BEGIN_CONNECTION_LOCK(conn) < 0) {
334
348
  return -1;
@@ -1180,9 +1194,8 @@ _mysql_escape_string(
1180
1194
  static const char _mysql_string_literal__doc__[] =
1181
1195
  "string_literal(obj) -- converts object obj into a SQL string literal.\n\
1182
1196
  This means, any special SQL characters are escaped, and it is enclosed\n\
1183
- within single quotes. In other words, it performs:\n\
1184
- \n\
1185
- \"'%s'\" % escape_string(str(obj))\n\
1197
+ within single quotes. For bytes and bytearray, the byte contents are\n\
1198
+ escaped directly. Other objects are converted to strings first.\n\
1186
1199
  \n\
1187
1200
  Use connection.string_literal(obj), if you use it at all.\n\
1188
1201
  _mysql.string_literal(obj) cannot handle character sets.";
@@ -1207,6 +1220,16 @@ _mysql_string_literal(
1207
1220
  s = o;
1208
1221
  Py_INCREF(s);
1209
1222
  }
1223
+ else if (PyByteArray_Check(o)) {
1224
+ #ifdef Py_GIL_DISABLED
1225
+ Py_BEGIN_CRITICAL_SECTION(o);
1226
+ #endif
1227
+ s = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(o), PyByteArray_GET_SIZE(o));
1228
+ #ifdef Py_GIL_DISABLED
1229
+ Py_END_CRITICAL_SECTION();
1230
+ #endif
1231
+ if (!s) goto error;
1232
+ }
1210
1233
  else {
1211
1234
  PyObject *t = PyObject_Str(o);
1212
1235
  if (!t) goto error;
@@ -2587,13 +2610,14 @@ static void
2587
2610
  _mysql_ResultObject_dealloc(
2588
2611
  _mysql_ResultObject *self)
2589
2612
  {
2590
- PyObject *conn = self->conn;
2591
2613
  PyObject_GC_UnTrack((PyObject *)self);
2592
- if (conn != NULL) {
2614
+ /* Only an unbuffered result may need to read remaining rows from the connection. */
2615
+ bool lock_connection = self->use && self->result != NULL && self->conn != NULL;
2616
+ if (lock_connection) {
2593
2617
  BEGIN_RESULT_CONNECTION_LOCK(self);
2594
2618
  }
2595
2619
  mysql_free_result(self->result);
2596
- if (conn != NULL) {
2620
+ if (lock_connection) {
2597
2621
  END_RESULT_CONNECTION_LOCK(self);
2598
2622
  }
2599
2623
  _mysql_ResultObject_clear(self);
@@ -324,13 +324,13 @@ class Connection(_mysql.connection):
324
324
  applications.
325
325
  """
326
326
  t = type(o)
327
- if t is str:
327
+ if isinstance(o, str):
328
328
  s = self.string_literal(o.encode(self.encoding))
329
- elif t in (bytes, bytearray):
329
+ elif isinstance(o, (bytes, bytearray)):
330
330
  s = self._bytes_literal(o)
331
- elif t in (tuple, list):
331
+ elif t is tuple or t is list:
332
332
  s = self._tuple_literal(o)
333
- elif t in (set, frozenset):
333
+ elif t is set or t is frozenset:
334
334
  s = self._set_literal(o)
335
335
  else:
336
336
  s = self.escape(o, self.encoders)
@@ -0,0 +1,3 @@
1
+ __author__ = "Inada Naoki <songofacandy@gmail.com>"
2
+ __version__ = "2.3.2"
3
+ version_info = (2, 3, 2, "final", 0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mysqlclient
3
- Version: 2.3.1
3
+ Version: 2.3.2
4
4
  Summary: Python interface to MySQL
5
5
  Author-email: Inada Naoki <songofacandy@gmail.com>
6
6
  License-Expression: GPL-2.0-or-later
@@ -4,6 +4,17 @@ from MySQLdb import _mysql
4
4
  from MySQLdb.connections import Connection
5
5
 
6
6
 
7
+ @pytest.mark.parametrize("data", [b"", b"a'\x00\\\xffb"])
8
+ def test_string_literal_bytearray(data):
9
+ class Subclass(bytearray):
10
+ def __str__(self):
11
+ raise AssertionError("string_literal should use the byte contents")
12
+
13
+ expected = _mysql.string_literal(data)
14
+ assert _mysql.string_literal(bytearray(data)) == expected
15
+ assert _mysql.string_literal(Subclass(data)) == expected
16
+
17
+
7
18
  def test_result_type():
8
19
  with pytest.raises(TypeError):
9
20
  _mysql.result(b"xyz")
@@ -1,12 +1,14 @@
1
+ import enum
1
2
  import threading
2
3
  import time
4
+ from concurrent.futures import ThreadPoolExecutor
3
5
 
4
6
  import pytest
5
7
  from configdb import connection_factory, connection_kwargs
6
8
 
7
- from MySQLdb.connections import Connection
8
9
  from MySQLdb._exceptions import ProgrammingError
9
- from MySQLdb.constants import CLIENT
10
+ from MySQLdb.connections import Connection
11
+ from MySQLdb.constants import CLIENT, FIELD_TYPE
10
12
 
11
13
 
12
14
  @pytest.fixture
@@ -18,6 +20,69 @@ def conn():
18
20
  connection.close()
19
21
 
20
22
 
23
+ @pytest.mark.parametrize("sql_mode", ["", "NO_BACKSLASH_ESCAPES"])
24
+ def test_literal_str_enum(conn, sql_mode):
25
+ class Foo(str, enum.Enum):
26
+ BAR = "BAR"
27
+ BAZ = "BAZ"
28
+
29
+ conn.set_sql_mode(sql_mode)
30
+ assert conn.literal(Foo.BAR) == b"'BAR'"
31
+ assert conn.literal((Foo.BAR, Foo.BAZ)) == b"('BAR','BAZ')"
32
+ cursor = conn.cursor()
33
+ cursor.execute("SELECT %s", (Foo.BAR,))
34
+ assert cursor.fetchone() == ("BAR",)
35
+
36
+
37
+ @pytest.mark.parametrize("value", ["BAR", b"BAR"])
38
+ @pytest.mark.parametrize("binary_prefix", [False, True])
39
+ def test_literal_string_subclass(value, binary_prefix):
40
+ class Subclass(type(value)):
41
+ pass
42
+
43
+ with connection_factory(binary_prefix=binary_prefix) as conn:
44
+ assert conn.literal(Subclass(value)) == conn.literal(value)
45
+
46
+
47
+ @pytest.mark.parametrize("binary_prefix", [False, True])
48
+ def test_literal_bytearray_subclass(binary_prefix):
49
+ class Subclass(bytearray):
50
+ pass
51
+
52
+ data = b"A'\x00\\B"
53
+ value = Subclass(data)
54
+ with connection_factory(binary_prefix=binary_prefix) as conn:
55
+ assert conn.literal(value) == conn.literal(data)
56
+ cursor = conn.cursor()
57
+ cursor.execute("SELECT %s", (value,))
58
+ expected = data if binary_prefix else data.decode(conn.encoding)
59
+ assert cursor.fetchone() == (expected,)
60
+
61
+
62
+ @pytest.mark.parametrize("container_type", [tuple, list, set, frozenset])
63
+ def test_literal_container_subclass_converter(conn, container_type):
64
+ class Subclass(container_type):
65
+ pass
66
+
67
+ conn.encoders[Subclass] = lambda value, mapping: b"'custom'"
68
+ cursor = conn.cursor()
69
+ cursor.execute("SELECT %s", (Subclass(["BAR"]),))
70
+ assert cursor.fetchone() == ("custom",)
71
+
72
+
73
+ @pytest.mark.parametrize("set_type", [set, frozenset])
74
+ @pytest.mark.parametrize("sql_mode", ["", "NO_BACKSLASH_ESCAPES"])
75
+ @pytest.mark.parametrize("charset", ["utf8mb4", "latin1"])
76
+ def test_literal_set_escaping(set_type, sql_mode, charset):
77
+ value = "é' OR 1=1 -- \\"
78
+ with connection_factory(charset=charset, sql_mode=sql_mode) as conn:
79
+ cursor = conn.cursor()
80
+ cursor.execute("SELECT %s", (set_type([value]),))
81
+ assert cursor.fetchone() == (value,)
82
+ with pytest.raises(TypeError, match="set elements must be strings"):
83
+ conn.literal(set_type([1]))
84
+
85
+
21
86
  def test_multi_statements_default_true(conn):
22
87
  cursor = conn.cursor()
23
88
 
@@ -63,9 +128,7 @@ def test_executemany_fallback_connection_subclass_default():
63
128
  with MultiConnection(**connection_kwargs({})) as conn:
64
129
  assert conn.executemany_fallback == "multi"
65
130
 
66
- with MultiConnection(
67
- **connection_kwargs({"executemany_fallback": "loop"})
68
- ) as conn:
131
+ with MultiConnection(**connection_kwargs({"executemany_fallback": "loop"})) as conn:
69
132
  assert conn.executemany_fallback == "loop"
70
133
 
71
134
 
@@ -108,6 +171,41 @@ def test_connection_concurrent_use_raises(conn):
108
171
  assert thread_error is None
109
172
 
110
173
 
174
+ @pytest.mark.parametrize("use", [False, True])
175
+ def test_result_rejects_reinitialization(conn, use):
176
+ conn.query("SELECT 1 UNION ALL SELECT 2 ORDER BY 1")
177
+ result = conn.use_result() if use else conn.store_result()
178
+ with pytest.raises(ProgrammingError, match="already initialized"):
179
+ result.__init__(conn, not use)
180
+
181
+ assert result.fetch_row() == ((1,),)
182
+ del result # Leave the second row for cleanup.
183
+ conn.query("SELECT 3")
184
+ assert conn.store_result().fetch_row() == ((3,),)
185
+
186
+
187
+ def test_stored_result_dealloc_while_connection_locked(conn):
188
+ stored = []
189
+
190
+ def store_result():
191
+ conn.query("SELECT 1")
192
+ stored.append(conn.store_result())
193
+
194
+ with ThreadPoolExecutor(max_workers=1) as executor:
195
+ # On free-threaded CPython, drop the last reference on its owning thread.
196
+ executor.submit(store_result).result()
197
+
198
+ def convert(value):
199
+ # fetch_row holds the connection lock while calling this converter.
200
+ executor.submit(stored.clear).result(timeout=5)
201
+ return int(value)
202
+
203
+ conn.converter[FIELD_TYPE.NEWDECIMAL] = convert
204
+ conn.query("SELECT CAST(2 AS DECIMAL(1,0))")
205
+ assert conn.use_result().fetch_row() == ((2,),)
206
+ assert not stored
207
+
208
+
111
209
  def test_result_concurrent_use_raises(conn):
112
210
  """While fetch_row holds the connection lock streaming a slow result,
113
211
  any other access from a second thread must raise ProgrammingError immediately."""
@@ -1,3 +0,0 @@
1
- __author__ = "Inada Naoki <songofacandy@gmail.com>"
2
- __version__ = "2.3.1"
3
- version_info = (2, 3, 1, "final", 0)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes