Opened 8 years ago
Closed 8 years ago
#29251 closed Bug (fixed)
MySQL backend returns bytes instead of strings in some queries involving database functions
| Reported by: | Mariusz Felisiak | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | mysql bytes |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
PR 9808 revealed a bug in the MySQL backend. mysqlclient returns bytes instead of strings in some edge cases, e.g.:
LPad('name', Length('alias'))
Replace('name', Length('alias'))
Change History (7)
comment:1 by , 8 years ago
| Owner: | changed from to |
|---|
comment:2 by , 8 years ago
| Description: | modified (diff) |
|---|---|
| Has patch: | set |
| Summary: | The MySQL back-end returns bytes instead of strings in some cases. → MySQL backend returns bytes instead of strings in some queries involving database functions |
| Triage Stage: | Unreviewed → Ready for checkin |
| Type: | Uncategorized → Bug |
comment:3 by , 8 years ago
Did you search for a MySQL ticket about this so we know if the behavior might change in future versions?
comment:4 by , 8 years ago
Yes, but I didn't find any specific tickets. I checked that mysql-connector-python behaves in the same way, then I noticed that MySQL returns different data types in both cases, i.e.
SELECT LPAD(`test_xyz`.`column1`, CHAR_LENGTH(`test_xyz`.`column2`), ' ') AS `filled` FROM `test_xyz`;returnsfilledas alongtext, probably because it cannot predict a no. of chars,SELECT LPAD(`test_xyz`.`column1`, 2, ' ') AS `filled` FROM `test_xyz`;returnsfilledas avarchar(2).
I also found related discussion https://github.com/django/django/pull/3754#discussion_r22146187 and following comment "...Looking briefly at the database driver, it appears that longtext/BLOB is defined as returning bytes...".
PR