Opened 10 years ago
Closed 10 years ago
#23628 closed Bug (wontfix)
AlterModelOptions should check for changes
Reported by: | no | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | github@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Consider the following model:
PERM_DEFS = { ('perm1', 'Desc1') : 123, ('perm2', 'Desc2') : 321 } class Spam(models.Model): class Meta: permissions = list(PERM_DEFS.keys())
Currently, running makemigrations
will always generate a new migration even though the permissions list doesn't change. Perhaps the inspector could do a set(old_attr) == set(new_attr)
type operation on list style attributes such as permissions
and default_permissions
.
Current workaround is: permissions = list(sorted(PERM_DEFS.keys()))
Change History (3)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
I don't think there's that much extra complexity: one possible solution: https://github.com/django/django/pull/3356
comment:3 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I don't think there's a good reason to say the ordering of permissions isn't important. For example, you might have a migration that indexes the permissions tuple to get a particular permission. Using sorted()
as Baptiste suggested seems like the best solution to me.
Hi,
This actually depends on your Python version.
On Python 3.3 and later, the order of dictionaries will change between different runs (that feature is called "hash randomization" if you want to look deeper).
On earlier versions of Python though, that order is consistent so the autodetector doesn't see any changes and no new migrations are created.
I'm not sure if this warrants the additional code complexity.
If you need a consistent order here you could use an
OrderedDict
or userpermissions = sorted(PERM_DEFS.keys())
.