#20932: Issues with model Manager and inheritance.
-------------------------------------+-------------------------------------
Reporter: loic84 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by poleha):
I don't try to enforce anything in
[https://code.djangoproject.com/ticket/25897/ #25897], I simply want to
fix the existing approach, which doesn't work as expected. I think that
the developer, who coded the current approach, was intended to achieve
what would be achieved if [https://code.djangoproject.com/ticket/25897,
#25897] would be applied.
Do you suggest removing all the code about contributing managers to models
and simple use regular python inheritance?
I must confess I like it and I thought of it many times while examining
the current approach. Python inheritance works well and it's predictable.
There's some login behind current approach, which is described in
[https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-
managers-and-model-inheritance/ documentation], but I am not sure that it
worth breaking regular python mro.
Replying to [comment:10 loic]:
> OK this boils down to `AbstractEvent.events` being inherited by
`MessyBachelorParty` despite having `BachelorParty` in between, hence why
`MessyBachelorParty.objects` doesn't exist.
>
> There is a design question here, should models inherit from managers of
abstract models no matter what, or should we consider inheritance must
stop when it hits a concrete parents.
>
> Since Django inheritance mimics Python inheritance to a large degree I
wonder more and more if we shouldn't always copy managers and revise the
docs. #25897 tries to enforce the documented behaviour by masking managers
at runtime, but that's fighting against standard Python inheritance (which
doesn't support private members).
>
> Can anyone see downsides to inheriting managers from concrete parents?
--
Ticket URL: <https://code.djangoproject.com/ticket/20932#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.d17116fc19c119038d56ff8d36e4fec2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.