summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2017-04-07 09:44:28 +0100
committerTim Graham <timograham@gmail.com>2017-05-01 09:32:44 -0400
commit63afe3a2bfaf97fecff6641137a85296029d5b73 (patch)
tree2e5a9abdb7665df9a5c6f7c042e85d36e7e60fff /django
parent4b0211dad55fc9d154dd5fc5b0006a647115d75d (diff)
Fixed #28043 -- Prevented AddIndex and RemoveIndex from mutating model state.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/models.py6
-rw-r--r--django/db/migrations/state.py3
2 files changed, 8 insertions, 1 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index f2b90c11e3..08cf6e314b 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -760,7 +760,10 @@ class AddIndex(IndexOperation):
def state_forwards(self, app_label, state):
model_state = state.models[app_label, self.model_name_lower]
- model_state.options[self.option_name].append(self.index)
+ indexes = list(model_state.options[self.option_name])
+ indexes.append(self.index.clone())
+ model_state.options[self.option_name] = indexes
+ state.reload_model(app_label, self.model_name_lower, delay=True)
def database_forwards(self, app_label, schema_editor, from_state, to_state):
model = to_state.apps.get_model(app_label, self.model_name)
@@ -802,6 +805,7 @@ class RemoveIndex(IndexOperation):
model_state = state.models[app_label, self.model_name_lower]
indexes = model_state.options[self.option_name]
model_state.options[self.option_name] = [idx for idx in indexes if idx.name != self.name]
+ state.reload_model(app_label, self.model_name_lower, delay=True)
def database_forwards(self, app_label, schema_editor, from_state, to_state):
model = from_state.apps.get_model(app_label, self.model_name)
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index bda077f318..e52f322e2d 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -546,6 +546,9 @@ class ModelState:
app_label=self.app_label,
name=self.name,
fields=list(self.fields),
+ # Since options are shallow-copied here, operations such as
+ # AddIndex must replace their option (e.g 'indexes') rather
+ # than mutating it.
options=dict(self.options),
bases=self.bases,
managers=list(self.managers),