Bug #97723 Parsing TEXT field returns wrong data type in python
Submitted: 20 Nov 2019 22:18 Modified: 10 May 2022 22:09
Reporter: Nicholas Lee-Hone Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:8.0.16, 8.0.18 OS:Any
Assigned to: CPU Architecture:Any

[20 Nov 2019 22:18] Nicholas Lee-Hone
Description:
The following diff going from 8.0.15 to 8.0.16 caused an issue where TEXT fields get parsed as either float or int data types if the TEXT contains only a number.

-        if dsc is not None:
-            if dsc[7] & FieldFlag.BINARY:
-                if PY2:
-                    return value
-                elif isinstance(value, str):
-                    return bytes(value, self.charset)
-                return bytes(value)
-
-        return self._STRING_to_python(value, dsc)
-
-    _LONG_BLOB_to_python = _JSON_to_python
+        if not value:
+            # This is an empty BLOB
+            return ""
+        # JSON Values are stored in LONG BLOB, but the blob values recived
+        # from the server are not dilutable, check for JSON values.
+        return self._JSON_to_python(value, dsc)
+
+    _LONG_BLOB_to_python = _BLOB_to_python

def _JSON_to_python(self, value, dsc=None):  # pylint: disable=C0103
        """Returns JSON column type as python type
        Returns JSON column type as python type.
        """
        try:
            num = float(value)
            if num.is_integer():
                return int(value)
            return num
        except ValueError:
            pass
        <MORE CODE BELOW>

How to repeat:
Save an integer or a float to a TEXT field.

Query the field and check the data type.

Suggested fix:
Remove the try block where float/int coercion is attempted.

or

Process TEXT blocks and BLOB blocks seperately.
[22 Nov 2019 4:37] MySQL Verification Team
Hello Nicholas Lee-Hone,

Thank you for the report.

regards,
Umesh
[31 Jan 2020 22:00] Nicholas Lee-Hone
Can we get an update on this issue? This is blocking us from upgrading to the latest version of mysql connector.
[10 May 2022 22:09] Philip Olson
It appears this old bug was missed; it was fixed in 8.0.24 via MySQL Bug #97177. Adding this bug number to that release note, sorry for the delay!