Opened 11 years ago

Last modified 9 years ago

#20932 closed Bug

Issues with model Manager and inheritance. — at Initial Version

Reported by: loic84 Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: manager-inheritance
Cc: Anssi Kääriäinen, LaurensBER, aronp@…, Marc Tamlyn Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've found a couple of issues with the current handling of managers with inheritance.

  1. Weird bug that I can't explain yet: https://github.com/loic/django/compare/manager_inheritance_bug

model_inheritance_regress.tests.ModelInheritanceTest.test_abstract_base_class_m2m_relation_inheritance fails with AttributeError: 'BachelorParty' object has no attribute 'bachelorparty_ptr'.

  1. Managers in MTI *are* inherited, contrary to what is said in the docs.

Quoting the docs: "Managers defined on non-abstract base classes are not inherited by child classes. [...] Therefore, they aren’t passed onto child classes.". The problem is that, since we create the new class by calling object.__new__(), normal Python attribute resolution applies, and we gain access to the attributes of the base classes. This doesn't happen to fields because these are removed during the class creation process, but managers are left behind. It's always tempting to think we could just delete them, but you cannot delete something that is not in your own __dict__. The problem is not so much that we inherit those managers, but that they don't return the right model type as demonstrated in https://github.com/loic/django/compare/manager_inheritance_bug2.

Note: I know we usually should have one ticket for each bug. This time though, we only have a couple of lines of codes that have multiple consequences, so I'd like to keep the discussion centralized. We can always open a ticket for each bug when the time comes to actually implement what we decide.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top