Bug #104744 mysql-connector-python throws exception when custom converter class used
Submitted: 26 Aug 2021 21:06 Modified: 30 Sep 2021 15:56
Reporter: Dima P Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:8.0.25, 8.0.26 OS:Any
Assigned to: CPU Architecture:Any
Tags: python

[26 Aug 2021 21:06] Dima P
Description:
Python connector throws exception in conversion of STRING fields:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    cursor.fetchall()
  File "C:\Users\dima\Miniconda3\envs\bug\lib\site-packages\mysql\connector\cursor_cext.py", line 510, in fetchall
    rows = self._cnx.get_rows()
  File "C:\Users\dima\Miniconda3\envs\bug\lib\site-packages\mysql\connector\connection_cext.py", line 344, in get_rows
    row[i])
  File "C:\Users\dima\Miniconda3\envs\bug\lib\site-packages\mysql\connector\conversion.py", line 204, in to_python
    return self._cache_field_types[vtype[1]](value, vtype)
  File "C:\Users\dima\Miniconda3\envs\bug\lib\site-packages\mysql\connector\conversion.py", line 592, in _STRING_to_python
    if dsc[8] == 63:  # 'binary' charset
IndexError: tuple index out of range

How to repeat:
CREATE TABLE `test` (
  `name` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO test VALUES ('test1', 'test2');

In python:
from mysql import connector
from mysql.connector.conversion import MySQLConverter

class MyConverter(MySQLConverter):
    pass

cnx = connector.connect(converter_class=MyConverter)
cursor = cnx.cursor()
cursor.execute('select * from test')
cursor.fetchall()

Suggested fix:
looks like CMySQLConnection.fetch_eof_columns in lib/mysql/connector/connection_cext.py is not appending a newly [since 8.0.24] field to the column descriptors.
[14 Sep 2021 10:30] MySQL Verification Team
Hello Dima,

Thank you for the bug report.
Verified as described.

Regards,
Ashwini Patil
[30 Sep 2021 15:56] Nuno Mariz
Posted by developer:
 
Fixed by WL#14689