From 4b02b433b75d457552ee37e519afe6c83f261d44 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Mon, 14 Dec 2015 01:20:10 -0500 Subject: [PATCH] [1.8.x] Fixed #25852 -- Made sure AlterModelManager forces a reload of its model state. Thanks to Geoffrey Sechter and the Django NYC group for the report and Markus for the review. Backport of c4e372aaf467ae41315cfe56a718a80469fc5318 from master --- django/db/migrations/operations/models.py | 1 + docs/releases/1.8.8.txt | 3 +++ tests/migrations/test_operations.py | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index c0eb92a0ef..fa4da99034 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -563,6 +563,7 @@ class AlterModelManagers(Operation): def state_forwards(self, app_label, state): model_state = state.models[app_label, self.name_lower] model_state.managers = list(self.managers) + state.reload_model(app_label, self.name_lower) def database_forwards(self, app_label, schema_editor, from_state, to_state): pass diff --git a/docs/releases/1.8.8.txt b/docs/releases/1.8.8.txt index 5dca5bccdb..6ba76d71cb 100644 --- a/docs/releases/1.8.8.txt +++ b/docs/releases/1.8.8.txt @@ -34,3 +34,6 @@ Bugfixes * Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and ``TextField`` respectively when using ``AlterField`` on PostgreSQL (:ticket:`25412`). + +* Fixed a state bug when using an ``AlterModelManagers`` operation + (:ticket:`25852`). diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 9849f66882..032fc44549 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -1378,6 +1378,11 @@ class OperationTests(OperationTestBase): self.assertEqual(managers[2][0], "food_mgr_kwargs") self.assertIsInstance(managers[2][1], FoodManager) self.assertEqual(managers[2][1].args, ("x", "y", 3, 4)) + rendered_state = new_state.apps + model = rendered_state.get_model('test_almoma', 'pony') + self.assertIsInstance(model.food_qs, models.Manager) + self.assertIsInstance(model.food_mgr, FoodManager) + self.assertIsInstance(model.food_mgr_kwargs, FoodManager) def test_alter_model_managers_emptying(self): """