summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-10-03 19:23:18 -0400
committerSimon Charette <charette.s@gmail.com>2016-10-04 08:35:15 -0400
commit040bd7c9387cfbf70a543c507b3b9eeb8f2725dc (patch)
tree76f66b1377e5254425d0bf6b157309fe9b93660c /django
parent3ab55c1a8a58ae6d6791cafbcefaf224d01ff314 (diff)
Fixed #27279 -- Fixed a migration performance regression related to RenameModel operations.
Thanks Trac alias mtomiyoshi for the report, Marten Kenbeek for the initial patch and Tim for the review.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/models.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index 027ebfe95a..a7024b5dde 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -278,6 +278,11 @@ class RenameModel(ModelOperation):
)
def state_forwards(self, app_label, state):
+ # In cases where state doesn't have rendered apps, prevent subsequent
+ # reload_model() calls from rendering models for performance
+ # reasons. This method should be refactored to avoid relying on
+ # state.apps (#27310).
+ reset_apps = 'apps' not in state.__dict__
apps = state.apps
model = apps.get_model(app_label, self.old_name)
model._meta.apps = apps
@@ -286,6 +291,8 @@ class RenameModel(ModelOperation):
f for f in model._meta.get_fields(include_hidden=True)
if f.auto_created and not f.concrete and (not f.hidden or f.many_to_many)
)
+ if reset_apps:
+ del state.__dict__['apps']
# Rename the model
state.models[app_label, self.new_name_lower] = state.models[app_label, self.old_name_lower]
state.models[app_label, self.new_name_lower].name = self.new_name