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).
(self)
| 258 | self.assertEqual(author_state.managers, []) |
| 259 | |
| 260 | def test_no_duplicate_managers(self): |
| 261 | """ |
| 262 | When a manager is added with `use_in_migrations = True` and a parent |
| 263 | model had a manager with the same name and `use_in_migrations = True`, |
| 264 | the parent's manager shouldn't appear in the model state (#26881). |
| 265 | """ |
| 266 | new_apps = Apps(["migrations"]) |
| 267 | |
| 268 | class PersonManager(models.Manager): |
| 269 | use_in_migrations = True |
| 270 | |
| 271 | class Person(models.Model): |
| 272 | objects = PersonManager() |
| 273 | |
| 274 | class Meta: |
| 275 | abstract = True |
| 276 | |
| 277 | class BossManager(PersonManager): |
| 278 | use_in_migrations = True |
| 279 | |
| 280 | class Boss(Person): |
| 281 | objects = BossManager() |
| 282 | |
| 283 | class Meta: |
| 284 | app_label = "migrations" |
| 285 | apps = new_apps |
| 286 | |
| 287 | project_state = ProjectState.from_apps(new_apps) |
| 288 | boss_state = project_state.models["migrations", "boss"] |
| 289 | self.assertEqual(boss_state.managers, [("objects", Boss.objects)]) |
| 290 | |
| 291 | def test_custom_default_manager(self): |
| 292 | new_apps = Apps(["migrations"]) |