[Django] #30172: Incorrect migration applying for new Meta.constraints/indexes and field check/unique or unique/index_together with same fields

7 views
Skip to first unread message

Django

unread,
Feb 10, 2019, 1:54:34 PM2/10/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together with same fields
------------------------------------------+------------------------
Reporter: Pavel Tyslacki | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
Case 1: trying remove check constraint from field when `CheckConstraint`
exists in `Meta.constraints` with same field will remove both constraints:
{{{
class TestCheck(models.Model):
f1 = models.PositiveIntegerField() # will change to `f1 =
models.IntegerField()`

class Meta:
constraints = [
models.CheckConstraint(check=models.Q(f1__gte=0),
name='TestCheck_f1_check'),
]


# initial migration:

migrations.CreateModel(
name='TestCheck',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('f1', models.PositiveIntegerField()),
],
),
migrations.AddConstraint(
model_name='testcheck',
constraint=models.CheckConstraint(check=models.Q(f1__gte=0),
name='TestCheck_f1_check'),
),

# applied migration:

migrations.AlterField(
model_name='testcheck',
name='f1',
field=models.IntegerField(),
),
}}}


Case 2: trying remove `unique=True` from field when `UniqueConstraint`
exists in `Meta.constraints` with same field will remove both constraints
or raise exception if `UniqueConstraint` has condition:
{{{
class TestUniqCondField(models.Model):
f1 = models.IntegerField(unique=True) # will change to `f1 =
models.IntegerField()`

class Meta:
constraints = [
models.UniqueConstraint(fields=['f1'],
name='TestUniqCondField_f1_uniq', condition=models.Q(f1__gte=0)),
]


# initial migration:

migrations.CreateModel(
name='TestUniqCondField',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('f1', models.IntegerField(unique=True)),
],
),
migrations.AddConstraint(
model_name='testuniqcondfield',
constraint=models.UniqueConstraint(condition=models.Q(f1__gte=0),
fields=('f1',), name='TestUniqCondField_f1_uniq'),
),


# applied migration:

migrations.AlterField(
model_name='testuniqcondfield',
name='f1',
field=models.IntegerField(),
),

}}}

Case 3: trying remove `Meta.unique_together` for same
`UniqueConstraint.fields` in `Meta.constraints` get incorrect state via
introspection (the same if UniqueConstraint has condition):
{{{
class TestUniqTogether(models.Model):
f1 = models.IntegerField()
f2 = models.IntegerField()

class Meta:
unique_together = [
('f1', 'f2'), # will be removed
]

constraints = [
models.UniqueConstraint(fields=['f1', 'f2'],
name='TestUniqTogether_f1_f2_uniq'),
]


# initial migration:

migrations.CreateModel(
name='TestUniqTogether',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('f1', models.IntegerField()),
('f2', models.IntegerField()),
],
),
migrations.AddConstraint(
model_name='testuniqtogether',
constraint=models.UniqueConstraint(fields=('f1', 'f2'),
name='TestUniqTogether_f1_f2_uniq'),
),
migrations.AlterUniqueTogether(
name='testuniqtogether',
unique_together={('f1', 'f2')},
),


# applied migration

migrations.AlterUniqueTogether(
name='testuniqtogether',
unique_together=set(),
),
}}}

Case 4: trying remove `Meta.index_together` for same `Index.fields` in
`Meta.indexes` get incorrect state via introspection (the same if Index
has condition):
{{{
class TestIndexTogether(models.Model):
f1 = models.IntegerField()
f2 = models.IntegerField()

class Meta:
index_together = [
('f1', 'f2'), # will be removed
]

indexes = [
models.Index(fields=['f1', 'f2'],
name='TestIndexTogether_f1_f2_index'),
]


# initial migration:

migrations.CreateModel(
name='TestIndexTogether',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('f1', models.IntegerField()),
('f2', models.IntegerField()),
],
),
migrations.AddIndex(
model_name='testindextogether',
index=models.Index(fields=['f1', 'f2'],
name='TestIndexTogether_f1_f2_index'),
),
migrations.AlterIndexTogether(
name='testindextogether',
index_together={('f1', 'f2')},
),


# applied migration:

migrations.AlterIndexTogether(
name='testindextogether',
index_together=set(),
),
}}}

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

Django

unread,
Feb 10, 2019, 2:02:53 PM2/10/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
--------------------------------+--------------------------------------

Reporter: Pavel Tyslacki | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

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

Django

unread,
Feb 11, 2019, 9:27:55 AM2/11/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
--------------------------------+------------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

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

* owner: nobody => Pavel Tyslacki
* status: new => assigned
* has_patch: 0 => 1


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

Django

unread,
Feb 11, 2019, 1:08:21 PM2/11/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
--------------------------------+------------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------
Changes (by Tim Graham):

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


Comment:

Can you look into the SQLite failures?

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

Django

unread,
Feb 11, 2019, 1:41:52 PM2/11/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
--------------------------------+------------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------

Comment (by Pavel Tyslacki):

Replying to [comment:3 Tim Graham]:


> Can you look into the SQLite failures?

Yep. Hope will fix soon.

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

Django

unread,
Mar 11, 2019, 6:13:55 AM3/11/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
--------------------------------+------------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2

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

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

* needs_better_patch: 1 => 0


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

Django

unread,
Mar 14, 2019, 9:40:47 PM3/14/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
-------------------------------------+-------------------------------------

Reporter: Pavel Tyslacki | Owner: Pavel
| Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* severity: Normal => Release blocker


Comment:

Marking as a release blocker since it's a bug in a new feature
(`Meta.constraints`).

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

Django

unread,
Mar 17, 2019, 9:28:57 PM3/17/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
-------------------------------------+-------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel
| Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"4bb859e24694f6cb8974ed9d2225f18214338ea3" 4bb859e]:
{{{
#!CommitTicketReference repository=""
revision="4bb859e24694f6cb8974ed9d2225f18214338ea3"
Refs #30172 -- Prevented removing a field's check or unique constraint
from removing Meta constraints.
}}}

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

Django

unread,
Mar 17, 2019, 9:28:57 PM3/17/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
-------------------------------------+-------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel
| Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"5c17c273ae2d7274f1fa78218b3b74690efddb86" 5c17c273]:
{{{
#!CommitTicketReference repository=""
revision="5c17c273ae2d7274f1fa78218b3b74690efddb86"
Refs #30172 -- Prevented removing a model Meta's index/unique_together
from removing Meta constraints/indexes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30172#comment:8>

Django

unread,
Mar 17, 2019, 9:53:30 PM3/17/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
-------------------------------------+-------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel
| Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"3dd5e71752c993df00e01fca8086a1af5ba89176" 3dd5e717]:
{{{
#!CommitTicketReference repository=""
revision="3dd5e71752c993df00e01fca8086a1af5ba89176"
[2.2.x] Refs #30172 -- Prevented removing a field's check or unique


constraint from removing Meta constraints.

Backport of 4bb859e24694f6cb8974ed9d2225f18214338ea3 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30172#comment:9>

Django

unread,
Mar 17, 2019, 9:53:31 PM3/17/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
-------------------------------------+-------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel
| Tyslacki
Type: Bug | Status: assigned
Component: Migrations | Version: 2.2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"2a92e2e3c12e5c4cad0ce2a2d5964675ef837fe7" 2a92e2e]:
{{{
#!CommitTicketReference repository=""
revision="2a92e2e3c12e5c4cad0ce2a2d5964675ef837fe7"
[2.2.x] Refs #30172 -- Prevented removing a model Meta's


index/unique_together from removing Meta constraints/indexes.

Backport of 5c17c273ae2d7274f1fa78218b3b74690efddb86 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30172#comment:10>

Django

unread,
Mar 17, 2019, 9:55:52 PM3/17/19
to django-...@googlegroups.com
#30172: Incorrect migration applying for new Meta.constraints/indexes and field
check/unique or unique/index_together constraints with same fields for
postgres
-------------------------------------+-------------------------------------
Reporter: Pavel Tyslacki | Owner: Pavel
| Tyslacki
Type: Bug | Status: closed
Component: Migrations | Version: 2.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

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


--
Ticket URL: <https://code.djangoproject.com/ticket/30172#comment:11>

Reply all
Reply to author
Forward
0 new messages