From 1e9b02a4c28142303fb4d33632e77ff7e26acb8b Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sat, 14 Jul 2018 11:56:19 -0400 Subject: [PATCH] Refs #28862 -- Removed the FieldRelatedOptionOperation.reduce() optimization. It isn't required anymore since AlterTogetherOperations can be reduced into CreateModels which can reduce DeleteField operations. --- django/db/migrations/operations/models.py | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index f286bf4ea4..18feb9b9a1 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -142,13 +142,22 @@ class CreateModel(ModelOperation): managers=self.managers, ), ] - elif isinstance(operation, FieldRelatedOptionOperation) and self.name_lower == operation.name_lower: - option_value = getattr(operation, operation.option_name) + elif isinstance(operation, AlterTogetherOptionOperation) and self.name_lower == operation.name_lower: return [ CreateModel( self.name, fields=self.fields, - options={**self.options, **{operation.option_name: option_value}}, + options={**self.options, **{operation.option_name: operation.option_value}}, + bases=self.bases, + managers=self.managers, + ), + ] + elif isinstance(operation, AlterOrderWithRespectTo) and self.name_lower == operation.name_lower: + return [ + CreateModel( + self.name, + fields=self.fields, + options={**self.options, 'order_with_respect_to': operation.order_with_respect_to}, bases=self.bases, managers=self.managers, ), @@ -481,17 +490,7 @@ class ModelOptionOperation(ModelOperation): return super().reduce(operation, app_label=app_label) -class FieldRelatedOptionOperation(ModelOptionOperation): - def reduce(self, operation, app_label=None): - if isinstance(operation, FieldOperation) and self.name_lower == operation.model_name_lower: - if isinstance(operation, RemoveField): - return False - if not self.references_field(operation.model_name, operation.name): - return [operation, self] - return super().reduce(operation, app_label=app_label) - - -class AlterTogetherOptionOperation(FieldRelatedOptionOperation): +class AlterTogetherOptionOperation(ModelOptionOperation): option_name = None def __init__(self, name, option_value): @@ -569,7 +568,7 @@ class AlterIndexTogether(AlterTogetherOptionOperation): super().__init__(name, index_together) -class AlterOrderWithRespectTo(FieldRelatedOptionOperation): +class AlterOrderWithRespectTo(ModelOptionOperation): """Represent a change with the order_with_respect_to option.""" option_name = 'order_with_respect_to'