Fixed #33572 -- Implemented CreateModel/AlterModelManagers reduction.

This commit is contained in:
Adam Johnson 2022-03-11 06:03:51 +00:00 committed by GitHub
parent 71017a68a6
commit 8f7cda0831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -170,6 +170,19 @@ class CreateModel(ModelOperation):
managers=self.managers,
),
]
elif (
isinstance(operation, AlterModelManagers)
and self.name_lower == operation.name_lower
):
return [
CreateModel(
self.name,
fields=self.fields,
options=self.options,
bases=self.bases,
managers=operation.managers,
),
]
elif (
isinstance(operation, AlterTogetherOptionOperation)
and self.name_lower == operation.name_lower

View File

@ -129,6 +129,30 @@ class OptimizerTests(SimpleTestCase):
],
)
def test_create_alter_model_managers(self):
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", fields=[]),
migrations.AlterModelManagers(
name="Foo",
managers=[
("objects", models.Manager()),
("things", models.Manager()),
],
),
],
[
migrations.CreateModel(
"Foo",
fields=[],
managers=[
("objects", models.Manager()),
("things", models.Manager()),
],
),
],
)
def test_create_model_and_remove_model_options(self):
self.assertOptimizesTo(
[