Bug #79623 [python 3, utf8] fetch_row() always returns 'bytes' instead 'str' for strings
Submitted: 14 Dec 2015 1:15 Modified: 6 May 2022 21:29
Reporter: Mykola Ulianytskyi Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:2.1.3 OS:CentOS (7.1)
Assigned to: CPU Architecture:Any

[14 Dec 2015 1:15] Mykola Ulianytskyi
Description:
Hi

- centos 7.1
- python 3.5.1
- mysql 5.7.10
- mysql-connector 2.1.3

python 3 + use_unicode=True + _mysql_connector: fetch_row() always returns 'bytes' instead 'str' for strings:

----------------------------------------------------------------
import _mysql_connector

cnx = _mysql_connector.MySQL(
    use_unicode     = True,
    raw             = False,
    charset_name    = 'utf8'
)

cnx.connect(
    host            = '127.0.0.1',
    database        = 'test',
    user            = 'test',
    password        = 'test',
)

cnx.query('SELECT name FROM _test')
row = cnx.fetch_row()
while row:
    print(row)
    row = cnx.fetch_row()

Output:
   (b'xxx',)
   (b'yyy',)
   (b'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82',)

----------------------------------------------------------------
CREATE TABLE `_test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

----------------------------------------------------------------

Is it possible to configure _mysql_connector to return 'str' instead of 'bytes' for strings?

Thank you

--
With best regards,
Mykola

How to repeat:
Always
[15 Dec 2015 6:57] Chiranjeevi Battula
Hello  Mykola Ulianytskyi,

Thank you for the bug report.
Verified this behavior on MySQL Connector/Python 2.1.3.

Thanks,
Chiranjeevi.
[15 Dec 2015 6:58] Chiranjeevi Battula
Output:

(b'chiran',)
(b'reddy',)
(b'chiranreddy',)
(b'reddychiran',)
(b'reddychiran',)
(b'xd0xbfxd1x80xd0xb8xd0xb2xd0xb5xd1x82',)
(b'xxx',)
(b'yyy',)
(b'zzz',)
[17 Dec 2015 5:38] Mykola Ulianytskyi
fetch_fields() also returns 'bytes':

cnx.query('SELECT name FROM _test')
print(cnx.fetch_fields())

[(b'def', b'test', b'_test', b'_test', b'name', b'name', 33, 0, 253, 128, 0)]

--
With best regards,
Mykola
[5 May 2022 11:05] Nuno Mariz
Posted by developer:
 
This issue is not reproducible in the latests releases of Connector/Python. Thank you for the bug report.
[6 May 2022 21:29] Philip Olson
This bug report was seemingly lost but was fixed at some point; we're sorry for the delay in status. Setting it to closed, thank you for the report!
[6 May 2022 21:37] Philip Olson
Update: it appears this was fixed in C/Python 8.0.12 when the C and Python implementations were evaluated for differences; and then fixed via worklog #11951. 

This bug number was added to that release note, thanks again!