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.
This commit is contained in:
Simon Charette 2015-12-14 01:20:10 -05:00
parent b7fdd60d85
commit c4e372aaf4
4 changed files with 12 additions and 0 deletions

View File

@ -590,6 +590,7 @@ class AlterModelManagers(Operation):
def state_forwards(self, app_label, state): def state_forwards(self, app_label, state):
model_state = state.models[app_label, self.name_lower] model_state = state.models[app_label, self.name_lower]
model_state.managers = list(self.managers) 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): def database_forwards(self, app_label, schema_editor, from_state, to_state):
pass pass

View File

@ -34,3 +34,6 @@ Bugfixes
* Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and * Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and
``TextField`` respectively when using ``AlterField`` on PostgreSQL ``TextField`` respectively when using ``AlterField`` on PostgreSQL
(:ticket:`25412`). (:ticket:`25412`).
* Fixed a state bug when using an ``AlterModelManagers`` operation
(:ticket:`25852`).

View File

@ -40,3 +40,6 @@ Bugfixes
* Fixed evaluation of zero-length slices of ``QuerySet.values()`` * Fixed evaluation of zero-length slices of ``QuerySet.values()``
(:ticket:`25894`). (:ticket:`25894`).
* Fixed a state bug when using an ``AlterModelManagers`` operation
(:ticket:`25852`).

View File

@ -1393,6 +1393,11 @@ class OperationTests(OperationTestBase):
self.assertEqual(managers[2][0], "food_mgr_kwargs") self.assertEqual(managers[2][0], "food_mgr_kwargs")
self.assertIsInstance(managers[2][1], FoodManager) self.assertIsInstance(managers[2][1], FoodManager)
self.assertEqual(managers[2][1].args, ("x", "y", 3, 4)) 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): def test_alter_model_managers_emptying(self):
""" """