From d3a935f01f6cb36d21b09d81c5f022a3a5116ab0 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Mon, 30 Jan 2017 13:26:54 -0500 Subject: [PATCH] Refs #27768 -- Reversed order of optimized and in-between operations. Operations can only be optimized through if they don't reference any of the state the operation they are compared against defines or alters, so it's safe to reverse the order. --- django/db/migrations/optimizer.py | 5 +++-- tests/migrations/test_autodetector.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django/db/migrations/optimizer.py b/django/db/migrations/optimizer.py index d31ab89d07..26ac88a221 100644 --- a/django/db/migrations/optimizer.py +++ b/django/db/migrations/optimizer.py @@ -47,9 +47,10 @@ class MigrationOptimizer: in_between = operations[i + 1:i + j + 1] result = operation.reduce(other, in_between, app_label) if isinstance(result, list): - # Optimize! Add result, then remaining others, then return - new_operations.extend(result) + # Add operations optimized through, optimized operations, + # and the remaining ones. new_operations.extend(in_between) + new_operations.extend(result) new_operations.extend(operations[i + j + 2:]) return new_operations if not result: diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 1fde1ba466..5ad32e610c 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -1165,8 +1165,8 @@ class AutodetectorTests(TestCase): # Right number/type of migrations? self.assertNumberMigrations(changes, 'testapp', 1) self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel", "CreateModel"]) - self.assertOperationAttributes(changes, "testapp", 0, 0, name="Author") - self.assertOperationAttributes(changes, "testapp", 0, 1, name="Publisher") + self.assertOperationAttributes(changes, "testapp", 0, 0, name="Publisher") + self.assertOperationAttributes(changes, "testapp", 0, 1, name="Author") self.assertMigrationDependencies(changes, 'testapp', 0, [("otherapp", "auto_1")]) # Right number/type of migrations? self.assertNumberMigrations(changes, 'otherapp', 2)