[Django] #30505: Ordering of Field.choices is significant for makemigrations

15 views
Skip to first unread message

Django

unread,
May 23, 2019, 2:19:23 PM5/23/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
--------------------------------------------+------------------------
Reporter: Marnanel Thurman | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: master
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 |
--------------------------------------------+------------------------
makemigrations regards the ordering of Field.choices as significant. The
docs require Field.choices to be an iterable, but not to be well-ordered.
If Field.choices is not well-ordered, then almost every run of
makemigrations will treat the model as changed, even without changes to
the code.

The ordering of Field.choices is not significant anywhere else, except as
a cosmetic detail in the admin.

This bug even occurs in
{{{
ACTIVITY_TYPES = set(['Create', 'Update', 'Delete'])

[....]
f_type = models.CharField(
max_length=255,
choices=[(x,x) for x in ACTIVITY_TYPES],
)
}}}

I would have expected the value of Field.choices here to be well-ordered
(and sorted) but makemigrations still flags this as changed every time.

I can put a test case together if you like.

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

Django

unread,
May 23, 2019, 3:22:34 PM5/23/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
----------------------------------+------------------------------------

Reporter: Marnanel Thurman | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

> I can put a test case together if you like.

Yes, please. Or a sample project that we can just run to play with.
(Pending that I'll assume it reproduces. 🙂)

I need to look deeper to see exactly what's going on here, but there's at
least a documentation issue:

> An iterable (e.g., a list or tuple) ...

If it's **required** to be ordered it should say `sequence` or similar.

I'd suspect it's just been assumed that a list or tuple would be used.
Maybe we can relax that. If not we'll have to change the docs.

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

Django

unread,
May 23, 2019, 3:25:28 PM5/23/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
----------------------------------+------------------------------------

Reporter: Marnanel Thurman | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master

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

* cc: Carlton Gibson (added)


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

Django

unread,
May 23, 2019, 4:36:22 PM5/23/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
----------------------------------+------------------------------------

Reporter: Marnanel Thurman | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master

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

* Attachment "ticket30505.tar.bz2" added.

Test case. Running makemigrations will create new migrations indefinitely

Django

unread,
May 27, 2019, 1:53:03 PM5/27/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
----------------------------------+---------------------------------------
Reporter: Marnanel Thurman | Owner: Caio Ariede
Type: Bug | Status: assigned
Component: Migrations | Version: master

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

* status: new => assigned
* owner: nobody => Caio Ariede


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

Django

unread,
May 27, 2019, 3:05:39 PM5/27/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
----------------------------------+---------------------------------------
Reporter: Marnanel Thurman | Owner: Caio Ariede
Type: Bug | Status: assigned
Component: Migrations | Version: master

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 Caio Ariede):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
May 29, 2019, 6:07:06 AM5/29/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
-------------------------------------+-------------------------------------

Reporter: Marnanel Thurman | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: assigned
Component: Migrations | Version: master

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

* has_patch: 1 => 0
* type: Bug => Cleanup/optimization


Comment:

This should be clarified in documentation, maybe "{{{A
:term:`sequence`}}}" instead of "{{{An iterable ...}}}" or a note about
ordering.

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

Django

unread,
May 29, 2019, 8:24:03 AM5/29/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
-------------------------------------+-------------------------------------
Reporter: Marnanel Thurman | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: assigned
Component: Migrations | Version: master

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 Caio Ariede):

* has_patch: 0 => 1


Comment:

new [https://github.com/django/django/pull/11429 PR]

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

Django

unread,
Jun 4, 2019, 8:57:38 AM6/4/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
-------------------------------------+-------------------------------------
Reporter: Marnanel Thurman | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: closed
Component: Migrations | Version: master
Severity: Normal | 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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"5248abe9b0425c1fc989c60a55860cdb4d135bcf" 5248abe9]:
{{{
#!CommitTicketReference repository=""
revision="5248abe9b0425c1fc989c60a55860cdb4d135bcf"
Fixed #30505 -- Doc'd how changes in the order of Field.choices affect
migrations.
}}}

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

Django

unread,
Jun 4, 2019, 8:58:06 AM6/4/19
to django-...@googlegroups.com
#30505: Ordering of Field.choices is significant for makemigrations
-------------------------------------+-------------------------------------
Reporter: Marnanel Thurman | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: closed
Component: Migrations | Version: master

Severity: Normal | 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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"d6d65c1e87d0da52e43d6359290a7b3f77367576" d6d65c1]:
{{{
#!CommitTicketReference repository=""
revision="d6d65c1e87d0da52e43d6359290a7b3f77367576"
[2.2.x] Fixed #30505 -- Doc'd how changes in the order of Field.choices
affect migrations.

Backport of 5248abe9b0425c1fc989c60a55860cdb4d135bcf from master
}}}

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

Reply all
Reply to author
Forward
0 new messages