#25897 closed Bug (fixed)
Managers defined on non-abstract base classes are in fact inherited by child classes.
Reported by: | Alex Poleha | Owned by: | Alex Poleha |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Normal | Keywords: | manager-inheritance |
Cc: | aronp@…, Loic Bistuer | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Although documentation says it shouldn't: https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers-and-model-inheritance
Change History (13)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | master → 1.8 |
comment:3 by , 9 years ago
Has patch: | set |
---|
follow-up: 5 comment:4 by , 9 years ago
Is there any indication this is a regression such that the fix should be backported or should we instead correct older versions of the documentation?
comment:5 by , 9 years ago
Replying to timgraham:
Is there any indication this is a regression such that the fix should be backported or should we instead correct older versions of the documentation?
I found mentioning this:
Managers defined on non-abstract base classes are not inherited by child classes
in documentation since version 1.4:
https://docs.djangoproject.com/en/1.4/topics/db/managers/#custom-managers-and-model-inheritance
And this bug exists in all versions since 1.4.
I think that fixing this bug in current version without fixing the documentation would be enough. But I am ready to provide path for all versions since 1.4. And I don't think that fixing old versions of documentation would be correct in this case.
comment:6 by , 9 years ago
Looking at the original commit where the documentation was added, f31425e8e23621fd4329c7377c9e220f526a1c49, it looks like named managers were always inherited. What does seem to work is that the default manager is never inherited.
The test case in the commit looks like this:
class Parent(models.Model): manager = OnlyFred() # Will not inherit default manager from parent. class Child7(Parent): pass >>> Parent._default_manager.all() [<Parent: fred>] >>> Child7._default_manager.order_by('name') [<Child7: barney>, <Child7: fred>] >>> Child7.manager.all() [<Parent: fred>] >>> Child7._default_manager.order_by('name') [<Child7: barney>, <Child7: fred>]
I wonder if the behavior should actually be changed (which will cause backwards incompatibility for anyone relying on it) or if the documentation should be fixed? Maybe we should ask on the DevelopersMailingList.
comment:7 by , 9 years ago
Patch needs improvement: | set |
---|
There hasn't been any immediate feedback on the mailing list except for me suggesting to put this through the deprecation cycle. The patch is updated for that but needs documentation as noted on the pull request.
comment:9 by , 9 years ago
Cc: | added |
---|
comment:10 by , 8 years ago
Keywords: | manager-inheritance added; manager inheritance removed |
---|
comment:11 by , 8 years ago
PR6175 revamps manager inheritance and inheriting managers from non-abstract base classes is the new expected behavior.
steps to reproduce: