summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-04-05 01:26:13 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-07 09:20:46 +0200
commitad811335bdd57d65dddbc05375ec3a70b59c96fb (patch)
treeaa381f0e25685ec54a1dedca902069d354ecddf8
parent1d16c5d562a67625f7309cc7765b8c57d49bf182 (diff)
Refs #29000 -- Restored delayed model rendering of RenameField.
Non-delayed rendering is unnecessary and wasteful now that state models relationship consistency on delayed reload is ensured. This partly reverts commit fcc4e251dbc917118f73d7187ee2f4cbf3883f36.
-rw-r--r--django/db/migrations/operations/fields.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/django/db/migrations/operations/fields.py b/django/db/migrations/operations/fields.py
index 6318c91d05..86e44e822f 100644
--- a/django/db/migrations/operations/fields.py
+++ b/django/db/migrations/operations/fields.py
@@ -304,11 +304,16 @@ class RenameField(FieldOperation):
# Rename the field
fields = model_state.fields
found = False
- delay = True
for index, (name, field) in enumerate(fields):
if not found and name == self.old_name:
fields[index] = (self.new_name, field)
found = True
+ # Delay rendering of relationships if it's not a relational
+ # field and not referenced by a foreign key.
+ delay = (
+ not field.is_relation and
+ not is_referenced_by_foreign_key(state, self.model_name_lower, field, self.name)
+ )
# Fix from_fields to refer to the new field.
from_fields = getattr(field, 'from_fields', None)
if from_fields:
@@ -316,12 +321,6 @@ class RenameField(FieldOperation):
self.new_name if from_field_name == self.old_name else from_field_name
for from_field_name in from_fields
])
- # Delay rendering of relationships if it's not a relational
- # field and not referenced by a foreign key.
- delay = delay and (
- not field.is_relation and
- not is_referenced_by_foreign_key(state, self.model_name_lower, field, self.name)
- )
if not found:
raise FieldDoesNotExist(
"%s.%s has no field named '%s'" % (app_label, self.model_name, self.old_name)