#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
-------------------------------------+-------------------------------------
Changes (by mjtamlyn):

 * cc: mjtamlyn (added)


Comment:

 I think that backwards incompat is acceptable, and pretty natural. The end
 result here becomes easy to explain:

 - Resolve managers explicitly defined on all models you inherit from
 (irrespective of their abstract or concrete nature) using normal MRO
 - If there are no managers explicitly defined, create `objects =
 models.Manager()` as every model must have a manager.

 The guiding point being the implicit creation is a last resort.

 Because the existing behaviour is strange and incorrectly documented,
 there's no harm in rewriting it to make it logical. It should be easy to
 make loud warnings that `MessyBachelorParty.objects` is not defined as
 `MessyBachelorParty.events` is.

 ----

 The other alternative approach, which I have to say I quite like but would
 be more far reaching, is to effectively define `objects` on `Model` and
 let normal MRO do the rest (subject to model binding). This would mean
 every model has a manager called `objects`, which is either the default
 manager or a defined custom manager. We scrap `_default_manager` and just
 use objects as the default. This would be a much bigger backwards
 incompatibility, but in my experience whenever I do define a custom
 manager, I either call it `objects`, or call it something else and
 redefine `objects`. I find the disappearing nature of `objects` somewhat
 strange and magical. Such a change would need to be discussed on the
 mailing list, what I'm curious about is whether anyone actually has a
 concrete need for `objects` to disappear.

--
Ticket URL: <https://code.djangoproject.com/ticket/20932#comment:14>
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.ce5002aba35b4a6ef736ed2361907509%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to