Opened 7 years ago

Last modified 5 years ago

#10506 new Bug

Automatically use correct auto-manager class for inherited models

Reported by: mtredinnick Owned by: mtredinnick
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When creating a subclass of a model with a default manager that has use_for_related_fields = True, and if the subclass has no explicit manager set, we should use the class of the parent's manager. This is consistent with every other time we create an automatic manager (in fact, the docs added in r10057 hint that we already do this, but it's not quite true for subclasses yet).

For multiple base classes, we walk them all and choose the most derived manager satisfying this constraint. It should subclass all the other managers that also do. If there is no such manager (e.g. two different managers subclassing django.db.models.Manager), we raise an error and the user has to specify the default manager themselves. This is because there would be no way to ensure that an appropriate get_query_set() method id used

Using MRO to determine the class type is wrong, since a model that inherits from both an ordinary model and a gis model, in that order, needs a GeoManager (which already subclasses Manager, so we're fine).

When this is done, there's a "TODO" in the gis tests that can be removed, too (in a child model).

I'll get to this before 1.1, but I had to fix the first parts of this as part of some other yak-shaving and don't want to get distracted on this yet.

Change History (5)

comment:1 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Understand correct auto-manager class for inherited models to Automatically use correct auto-manager class for inherited models
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by mtredinnick

  • milestone 1.1 deleted

Given the work to do before 1.1, pushing this one to later.

comment:3 Changed 5 years ago by SmileyChris

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

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