diff options
| author | Simon Charette <charette.s@gmail.com> | 2017-01-30 13:26:54 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-07-11 10:49:50 -0400 |
| commit | d3a935f01f6cb36d21b09d81c5f022a3a5116ab0 (patch) | |
| tree | 532945dd8520fffabf2371577bf9fb5ca97466e7 | |
| parent | 529c3f264d99fff0129cb6afbe4be2eb11d8a501 (diff) | |
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.
| -rw-r--r-- | django/db/migrations/optimizer.py | 5 | ||||
| -rw-r--r-- | 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) |
