Opened 8 years ago
Closed 8 years ago
#26609 closed Bug (wontfix)
Spurious migrations caused by non-deteministic field choices order
Reported by: | Harry Percival | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Normal | Keywords: | migrations |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Not sure if this is *quite* a bug, but thought I'd mention it since it was a puzzler.
I had an app that seemed to be generatic infinite migrations, ie "makemigrations" would always create new migrations even if I didn't do anything about it.
Eventually I figured out it was (I think) due to Python's non-deterministic dict ordering behaviour (this may be Python 3 only, IIRC said nondetermininstic ordering is to avoid some sort of security thing).
code, eg:
THINGS = { 'key1': 'val1', 'key2': 'val2', #etc } # ... myfield = models.CharField(choices=[(k,v) for k,v in THINGS], max_length=255)
I fixed it by using "sorted" on my list comprehension, but I imagine other people might be v confused, and it feels like something ppl are quite likely to do (use a dict for the basis of choices in a field?)
Change History (3)
comment:1 Changed 8 years ago by
Summary: | Spurious migrations cause by non-deteministic field choices order → Spurious migrations caused by non-deteministic field choices order |
---|
comment:2 Changed 8 years ago by
comment:3 Changed 8 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I'm afraid there's not much we can do about it.
The choices
option is meant to be ordered and the migration framework correctly detects changes in ordering.
ah, i think it's not just python 3: https://mail.python.org/pipermail/python-announce-list/2012-March/009394.html