[Django] #29103: sqlmigrate produces byte literal in SQL for one-off empty string default value in TextField, CharField

11 views
Skip to first unread message

Django

unread,
Feb 2, 2018, 9:04:53 AM2/2/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off empty string default
value in TextField, CharField
-------------------------------------+-------------------------------------
Reporter: qlimax | Owner: nobody
Type: Bug | Status: new
Component: | Version: 2.0
Migrations | Keywords: sqlmigrate, byte,
Severity: Normal | default value, one-off
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{
$ python manage.py makemigrations myapp
You are trying to add a non-nullable field 'text1' to mytable without a
default; we can't do that (the database needs something to populate
existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a
null value for this column)
2) Quit, and let me add a default in models.py
Select an option: 1
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can
do e.g. timezone.now
Type 'exit' to exit this prompt
>>> ''
Migrations for 'myapp':
myapp/migrations/0003_somechange.py
- Add field text1 to mytable

Done.

$ python manage.py sqlmigrate myapp 0003_somechange
BEGIN;
--
-- Add field text1 to mytable
--
ALTER TABLE `myapp_mytable` ADD COLUMN `text1` longtext NOT NULL;
UPDATE `myapp_mytable` SET `text1` = b"''";
COMMIT;

$ cat myapp/migrations/0003_somechange.py
# Generated by Django 2.0.2 on 2018-02-02 11:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('myapp', '0002_auto_20180202_1154'),
]

operations = [
migrations.AddField(
model_name='mytable',
name='text1',
field=models.TextField(default=''),
preserve_default=False,
),
]
$ python --version
Python 3.4.2
}}}

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

Django

unread,
Feb 2, 2018, 9:09:03 AM2/2/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in

TextField, CharField
-------------------------------------+-------------------------------------
Reporter: qlimax | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: sqlmigrate, byte, | Triage Stage:
default value, one-off | Unreviewed
Has patch: 0 | Needs documentation: 0

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

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

Django

unread,
Feb 2, 2018, 12:43:04 PM2/2/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in
TextField, CharField on MySQL
-------------------------------------+-------------------------------------
Reporter: Qlimax | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: sqlmigrate, byte, | Triage Stage: Accepted
default value, one-off |
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted
* easy: 1 => 0


Comment:

This is MySQL-specific. I couldn't quickly locate where the problem is.

--
Ticket URL: <https://code.djangoproject.com/ticket/29103#comment:2>

Django

unread,
Feb 9, 2018, 11:02:39 AM2/9/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in
TextField, CharField on MySQL
-------------------------------------+-------------------------------------
Reporter: Qlimax | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: sqlmigrate, byte, | Triage Stage: Accepted
default value, one-off |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9680 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29103#comment:3>

Django

unread,
Feb 12, 2018, 3:08:19 PM2/12/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in
TextField, CharField on MySQL
-------------------------------------+-------------------------------------
Reporter: Qlimax | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: sqlmigrate, byte, | Triage Stage: Accepted
default value, one-off |
Has patch: 1 | Needs documentation: 0

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

Comment (by Claude Paroz):

It's still not entirely clear to me what is the correct expected output. I
think that internally, mysqlclient is using the `'surrogateescape'`
encoding which is apparently not usable for some outputs like the shell.
Any suggestion welcome.

--
Ticket URL: <https://code.djangoproject.com/ticket/29103#comment:4>

Django

unread,
Feb 12, 2018, 4:27:29 PM2/12/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in
TextField, CharField on MySQL
-------------------------------------+-------------------------------------
Reporter: Qlimax | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: sqlmigrate, byte, | Triage Stage: Accepted
default value, one-off |
Has patch: 1 | Needs documentation: 0

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

Comment (by Claude Paroz):

Ah sorry, in the current use case, the expected output is simply no binary
marker, which is fixed in my patch.
My question is about the SQL output in the hypothetic case the default
would be a real binary bytestring.

--
Ticket URL: <https://code.djangoproject.com/ticket/29103#comment:5>

Django

unread,
Mar 14, 2018, 9:01:11 AM3/14/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in
TextField, CharField on MySQL
-------------------------------------+-------------------------------------
Reporter: Qlimax | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: sqlmigrate, byte, | Triage Stage: Ready for
default value, one-off | checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29103#comment:6>

Django

unread,
Mar 17, 2018, 5:22:19 PM3/17/18
to django-...@googlegroups.com
#29103: sqlmigrate produces byte literal in SQL for one-off string default value in
TextField, CharField on MySQL
-------------------------------------+-------------------------------------
Reporter: Qlimax | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 2.0
Severity: Normal | Resolution: fixed

Keywords: sqlmigrate, byte, | Triage Stage: Ready for
default value, one-off | checkin
Has patch: 1 | Needs documentation: 0

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

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"3c4ff2176323dd20507e35658599da220fbe1741" 3c4ff217]:
{{{
#!CommitTicketReference repository=""
revision="3c4ff2176323dd20507e35658599da220fbe1741"
Fixed #29103 -- Removed bad 'b'-prefix added by MySQL's
SchemaEditor.quote_value().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29103#comment:7>

Reply all
Reply to author
Forward
0 new messages