Bug #77822 Can`t UPDATE "binary" mysql-field with Python "bytearray" data.
Submitted: 23 Jul 2015 22:23 Modified: 9 Feb 2016 16:51
Reporter: Vitalii Lishcheniuk Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S1 (Critical)
Version:2.0.4 OS:Windows
Assigned to: CPU Architecture:Any

[23 Jul 2015 22:23] Vitalii Lishcheniuk
Description:
When INSERT\UPDATE to field of type "binary" with python data of type "bytearray" I have got an error:

File "c:\python34\lib\site-packages\mysql\connector\cursor.py", line 379, in _process_params
"Failed processing format-parameters; %s" % err
Failed processing format-parameters; can`t concat bytes to str

How to repeat:
Create MySQL table with field of type "binary", insert any binary data. Then read the data from MySQL to Python variable and write it back from Python to MySQL field.

Suggested fix:
In module mysql/connector/conversion.py change the code (lines 200-202) from:

    def _bytearray_to_mysql(self, value):
        """Convert value to bytes"""
        return str(value)

to:

    def _bytearray_to_mysql(self, value):
        """Convert value to bytes"""
        return bytes(value)
[24 Jul 2015 8:26] Peeyush Gupta
Verified.

Thanks for your bug report.
[9 Feb 2016 16:51] Paul DuBois
Noted in 2.1.4 changelog.

Attempts to insert Python ByteArray data into binary table columns
failed.
[9 Feb 2022 22:47] Nuno Mariz
Posted by developer:
 
The issue still remains when using the c-ext implementation.
[28 Feb 2022 18:48] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/Python 8.0.29 release, and here's the proposed changelog entry from the documentation team:

Attempts to insert Python ByteArray data into binary table columns failed
when using the c-extension implementation of Connector/Python.

Thank you for the bug report.

Also updated the original release note to include an update about cext.