Skip to content

Commit

Permalink
try to fix broken conv
Browse files Browse the repository at this point in the history
  • Loading branch information
tltx committed Jan 3, 2024
1 parent a2212b3 commit f953913
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
35 changes: 18 additions & 17 deletions src/MySQLdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,27 @@ class object, used to create cursors (keyword only)
if "passwd" in kwargs2:
kwargs2["password"] = kwargs2.pop("passwd")

use_unicode = kwargs2.pop("use_unicode", True)
default_conversions = conversions.copy()
if not use_unicode:
for t in (

Check warning on line 166 in src/MySQLdb/connections.py

View check run for this annotation

Codecov / codecov/patch

src/MySQLdb/connections.py#L166

Added line #L166 was not covered by tests
FIELD_TYPE.STRING,
FIELD_TYPE.VAR_STRING,
FIELD_TYPE.VARCHAR,
FIELD_TYPE.TINY_BLOB,
FIELD_TYPE.MEDIUM_BLOB,
FIELD_TYPE.LONG_BLOB,
FIELD_TYPE.BLOB,
):
default_conversions[t] = bytes

Check warning on line 175 in src/MySQLdb/connections.py

View check run for this annotation

Codecov / codecov/patch

src/MySQLdb/connections.py#L175

Added line #L175 was not covered by tests
# Unlike other string/blob types, JSON is always text.
# MySQL may return JSON with charset==binary.
default_conversions[FIELD_TYPE.JSON] = bytes

Check warning on line 178 in src/MySQLdb/connections.py

View check run for this annotation

Codecov / codecov/patch

src/MySQLdb/connections.py#L178

Added line #L178 was not covered by tests

if "conv" in kwargs:
conv = kwargs["conv"]
else:
conv = conversions
conv = default_conversions

conv2 = {}
for k, v in conv.items():
Expand All @@ -176,7 +193,6 @@ class object, used to create cursors (keyword only)
cursorclass = kwargs2.pop("cursorclass", self.default_cursor)
charset = kwargs2.get("charset", "")
collation = kwargs2.pop("collation", "")
use_unicode = kwargs2.pop("use_unicode", True)
sql_mode = kwargs2.pop("sql_mode", "")
self._binary_prefix = kwargs2.pop("binary_prefix", False)

Expand Down Expand Up @@ -209,21 +225,6 @@ class object, used to create cursors (keyword only)
if sql_mode:
self.set_sql_mode(sql_mode)

if use_unicode:
for t in (
FIELD_TYPE.STRING,
FIELD_TYPE.VAR_STRING,
FIELD_TYPE.VARCHAR,
FIELD_TYPE.TINY_BLOB,
FIELD_TYPE.MEDIUM_BLOB,
FIELD_TYPE.LONG_BLOB,
FIELD_TYPE.BLOB,
):
self.converter[t] = _bytes_or_str
# Unlike other string/blob types, JSON is always text.
# MySQL may return JSON with charset==binary.
self.converter[FIELD_TYPE.JSON] = str

self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
if self._transactional:
if autocommit is not None:
Expand Down
16 changes: 8 additions & 8 deletions src/MySQLdb/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ def array2Str(o, d):
FIELD_TYPE.DATETIME: DateTime_or_None,
FIELD_TYPE.TIME: TimeDelta_or_None,
FIELD_TYPE.DATE: Date_or_None,
FIELD_TYPE.TINY_BLOB: bytes,
FIELD_TYPE.MEDIUM_BLOB: bytes,
FIELD_TYPE.LONG_BLOB: bytes,
FIELD_TYPE.BLOB: bytes,
FIELD_TYPE.STRING: bytes,
FIELD_TYPE.VAR_STRING: bytes,
FIELD_TYPE.VARCHAR: bytes,
FIELD_TYPE.JSON: bytes,
FIELD_TYPE.TINY_BLOB: _bytes_or_str,
FIELD_TYPE.MEDIUM_BLOB: _bytes_or_str,
FIELD_TYPE.LONG_BLOB: _bytes_or_str,
FIELD_TYPE.BLOB: _bytes_or_str,
FIELD_TYPE.STRING: _bytes_or_str,
FIELD_TYPE.VAR_STRING: _bytes_or_str,
FIELD_TYPE.VARCHAR: _bytes_or_str,
FIELD_TYPE.JSON: str,
}

0 comments on commit f953913

Please sign in to comment.