summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLoïc Bistuer <loic.bistuer@gmail.com>2016-07-09 17:52:52 +0700
committerLoïc Bistuer <loic.bistuer@gmail.com>2016-07-09 18:12:18 +0700
commita2af2420ce8f4f2bf67e095740e62fa2d3c249cf (patch)
treebbfe2f06674a3235d007da98e62a0699931a2249 /tests
parentcf6f0e9978af750855d61fcee42ffc75c62c81f9 (diff)
[1.10.x] Fixed #26881 -- Fixed duplicate managers in migrations.
When both parent and child models had managers with the same name and a migrations opt-in both were added to the migration state. Backport of dab83e5ba108c08a04ae400ac5354fd73e26c6f5 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_state.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py
index d165221aa6..c8814a4296 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -210,6 +210,37 @@ class StateTests(SimpleTestCase):
author_state = project_state.models['migrations', 'author']
self.assertEqual(author_state.managers, [])
+ def test_no_duplicate_managers(self):
+ """
+ When a manager is added with `use_in_migrations = True` and a parent
+ model had a manager with the same name and `use_in_migrations = True`,
+ the parent's manager shouldn't appear in the model state (#26881).
+ """
+ new_apps = Apps(['migrations'])
+
+ class PersonManager(models.Manager):
+ use_in_migrations = True
+
+ class Person(models.Model):
+ objects = PersonManager()
+
+ class Meta:
+ abstract = True
+
+ class BossManager(PersonManager):
+ use_in_migrations = True
+
+ class Boss(Person):
+ objects = BossManager()
+
+ class Meta:
+ app_label = 'migrations'
+ apps = new_apps
+
+ project_state = ProjectState.from_apps(new_apps)
+ boss_state = project_state.models['migrations', 'boss']
+ self.assertEqual(boss_state.managers, [('objects', Boss.objects)])
+
def test_custom_default_manager(self):
new_apps = Apps(['migrations'])