#30505 closed Cleanup/optimization (fixed)
Ordering of Field.choices is significant for makemigrations
Reported by: | Marnanel Thurman | Owned by: | Caio Ariede |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Carlton Gibson | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (1)
Change History (9)
comment:1 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 6 years ago
Cc: | added |
---|
by , 6 years ago
Attachment: | ticket30505.tar.bz2 added |
---|
Test case. Running makemigrations will create new migrations indefinitely
comment:3 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 6 years ago
Has patch: | unset |
---|---|
Type: | Bug → Cleanup/optimization |
This should be clarified in documentation, maybe "A :term:`sequence`
" instead of "An iterable ...
" or a note about ordering.
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:
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.