[Django] #27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural into CreateModel

33 views
Skip to first unread message

Django

unread,
Jan 10, 2017, 1:03:01 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
--------------------------------------+----------------------------------
Reporter: Ed Morley | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords: squashmigrations
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+----------------------------------
The `squashmigrations` command doesn't combine a `AlterModelOptions()`
with `CreateModel()` in the case below.

For example (using Django master):

testapp/models.py

{{{#!python
from django.db import models


class Credentials(models.Model):
description = models.TextField()

class Meta:
db_table = 'credentials'
# This was added after 0001_initial.py was generated:
verbose_name_plural = 'credentials'
}}}

testapp/migrations/0001_initial.py

{{{#!python
class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Credentials',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('description', models.TextField()),
],
options={
'db_table': 'credentials',
},
),
]
}}}

testapp/migrations/0002_add_verbose_name_plural.py
{{{#!python
class Migration(migrations.Migration):

dependencies = [
('testapp', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='credentials',
options={'verbose_name_plural': 'credentials'},
),
]
}}}

Expected squashed migration (via `./manage.py squashmigrations testapp
0002`):
{{{#!python
class Migration(migrations.Migration):

replaces = [('testapp', '0001_initial'), ('testapp',
'0002_add_verbose_name_plural')]

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Credentials',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('description', models.TextField()),
],
options={
'db_table': 'credentials',
'verbose_name_plural': 'credentials',
},
),
]
}}}

Actual squashed migration:
{{{#!python
class Migration(migrations.Migration):

replaces = [('testapp', '0001_initial'), ('testapp',
'0002_add_verbose_name_plural')]

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Credentials',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('description', models.TextField()),
],
options={
'db_table': 'credentials',
},
),
migrations.AlterModelOptions(
name='credentials',
options={'verbose_name_plural': 'credentials'},
),
]
}}}

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

Django

unread,
Jan 10, 2017, 2:46:57 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
--------------------------------------+------------------------------------

Reporter: Ed Morley | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: squashmigrations | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Managed to reproduce with the provided patch.

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

Django

unread,
Jan 10, 2017, 2:47:34 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
--------------------------------------+------------------------------------

Reporter: Ed Morley | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: squashmigrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* Attachment "0001-Refs-27717-Added-a-regression-test.patch" added.

Django

unread,
Jan 10, 2017, 3:26:32 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
-------------------------------------+-------------------------------------
Reporter: Ed Morley | Owner: Ed Morley
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: squashmigrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ed Morley):

* status: new => assigned
* owner: nobody => Ed Morley


Comment:

Thank you for the testcase - PR with that and fix opened :-)

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

Django

unread,
Jan 10, 2017, 4:45:40 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
-------------------------------------+-------------------------------------
Reporter: Ed Morley | Owner: Ed Morley
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: squashmigrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


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

Django

unread,
Jan 10, 2017, 4:48:13 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
-------------------------------------+-------------------------------------
Reporter: Ed Morley | Owner: Ed Morley
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: squashmigrations | 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 Markus Holtermann):

* stage: Accepted => Ready for checkin


Comment:

Patch and tests look sensible to me.

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

Django

unread,
Jan 10, 2017, 6:39:08 PM1/10/17
to django-...@googlegroups.com
#27717: Squashmigrations doesn't optimize AlterModelOptions verbose_name_plural
into CreateModel
-------------------------------------+-------------------------------------
Reporter: Ed Morley | Owner: Ed Morley
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: squashmigrations | 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 <timograham@…>):

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


Comment:

In [changeset:"7156a6c9c47fe599207673e1653b056cc46082f6" 7156a6c9]:
{{{
#!CommitTicketReference repository=""
revision="7156a6c9c47fe599207673e1653b056cc46082f6"
Fixed #27717 -- Allowed migration optimization across AlterModelOptions.
}}}

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

Reply all
Reply to author
Forward
0 new messages