[Django] #29251: The MySQL back-end returns bytes instead of strings in some cases.

19 views
Skip to first unread message

Django

unread,
Mar 22, 2018, 1:34:26 PM3/22/18
to django-...@googlegroups.com
#29251: The MySQL back-end returns bytes instead of strings in some cases.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: nobody
Type: | Status: assigned
Uncategorized |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords: mysql bytes
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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'))```.

--
Ticket URL: <https://code.djangoproject.com/ticket/29251>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 22, 2018, 1:34:48 PM3/22/18
to django-...@googlegroups.com
#29251: The MySQL back-end returns bytes instead of strings in some cases.
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Uncategorized | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:

Keywords: mysql bytes | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* owner: nobody => felixxm


--
Ticket URL: <https://code.djangoproject.com/ticket/29251#comment:1>

Django

unread,
Mar 22, 2018, 9:36:07 PM3/22/18
to django-...@googlegroups.com
#29251: MySQL backend returns bytes instead of strings in some queries involving
database functions

-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Bug | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: mysql bytes | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
Mar 29, 2018, 3:36:16 PM3/29/18
to django-...@googlegroups.com
#29251: MySQL backend returns bytes instead of strings in some queries involving
database functions
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: mysql bytes | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 29, 2018, 5:01:45 PM3/29/18
to django-...@googlegroups.com
#29251: MySQL backend returns bytes instead of strings in some queries involving
database functions
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: mysql bytes | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 30, 2018, 5:26:11 AM3/30/18
to django-...@googlegroups.com
#29251: MySQL backend returns bytes instead of strings in some queries involving
database functions
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: mysql bytes | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Apr 2, 2018, 12:58:58 PM4/2/18
to django-...@googlegroups.com
#29251: MySQL backend returns bytes instead of strings in some queries involving
database functions
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: mysql bytes | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Apr 3, 2018, 12:24:27 PM4/3/18
to django-...@googlegroups.com
#29251: MySQL backend returns bytes instead of strings in some queries involving
database functions
-------------------------------------+-------------------------------------
Reporter: felixxm | Owner: felixxm
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: mysql bytes | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages