```LPad('name', Length('alias'))```,
```Replace('name', Length('alias'))```.
--
Ticket URL: <https://code.djangoproject.com/ticket/29251>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => felixxm
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:1>
* has_patch: 0 => 1
* type: Uncategorized => Bug
* stage: Unreviewed => Ready for checkin
Old description:
> PR [https://github.com/django/django/pull/9808 9808] revealed a bug in
> the MySQL back-end. `mysqlclient` returns `bytes` instead of `strings`
> in some edge cases, e.g.:
>
> ```LPad('name', Length('alias'))```,
> ```Replace('name', Length('alias'))```.
New description:
PR [https://github.com/django/django/pull/9808 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'))`
--
Comment:
[https://github.com/django/django/pull/9816 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:2>
Comment (by Tim Graham):
Did you search for a MySQL ticket about this so we know if the behavior
might change in future versions?
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:3>
Comment (by felixxm):
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`;}}} returns `filled` as a `longtext`,
probably because it cannot predict a no. of chars,
- {{{SELECT LPAD(`test_xyz`.`column1`, 2, ' ') AS `filled` FROM
`test_xyz`;}}} returns `filled` as a `varchar(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..."''.
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:4>
Comment (by felixxm):
IMO this behavior will not (cannot) be changed in the MySQL engine.
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:5>
Comment (by Tim Graham):
A [https://github.com/django/django/pull/9835 new PR] uses a different
approach.
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"6141c752fe7091d2197f5ac061300a9e0a36b09b" 6141c752]:
{{{
#!CommitTicketReference repository=""
revision="6141c752fe7091d2197f5ac061300a9e0a36b09b"
Fixed #29251 -- Added bytes to str conversion in LPad/RPad database
functions on MySQL.
Thanks Tim Graham for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:7>