[CONPY-140] CHAR column returns inconsistent Python types Created: 2021-02-05  Updated: 2021-02-14  Resolved: 2021-02-14

Status: Closed
Project: MariaDB Connector/Python
Component/s: DBAPI 2.0
Affects Version/s: 1.0.5
Fix Version/s: 1.0.6

Type: Bug Priority: Minor
Reporter: Lee Clemens Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

CentOS 7
MariaDB 10.5.8-MariaDB-log
Python 3.9.1



 Description   

Hello,

I noticed different types are returned when querying (at least) columns of VARCHAR and CHAR types depending upon prepared, but consistent for TEXT.

When the query is executed (not prepared), the connector returns `str` which is expected from my reading of PEP 249.

However, if `prepared=True` is used when creating the cursor, the returned values are of type `bytes` for VARCHAR and CHAR.

I would expect the returned types to be consistent, regardless of being a prepared statement.

https://gist.github.com/leeclemens/812027ba306363de61266135e31e30c9

Produces:

  Testing BASE_QRY
  [<class 'str'>, <class 'str'>]
  [<class 'str'>, <class 'str'>]
  Testing WHERE_QRY
  [<class 'str'>, <class 'str'>]
  Testing PREPARED_QRY
  [<class 'bytes'>, <class 'str'>]



 Comments   
Comment by Georg Richter [ 2021-02-14 ]

I don't think that this was fixed by CONC-139, but I'm not able to reproduce this issue with 1.0.6 from github:

 
Testing BASE_QRY
[<class 'str'>, <class 'str'>]
[<class 'str'>, <class 'str'>]
Testing WHERE_QRY
[<class 'str'>, <class 'str'>]
Testing PREPARED_QRY
[<class 'str'>, <class 'str'>]

Comment by Lee Clemens [ 2021-02-14 ]

Thank you, I have confirmed it is fixed by https://github.com/mariadb-corporation/mariadb-connector-python/commit/f633103914904ae61ed44297c76d9270a8aa7462

Generated at Thu Feb 08 03:30:33 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.