Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#27875 closed Bug (fixed)

Manager inheritance documentation doesn't mention manager_inheritance_from_future

Reported by: ek-init Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords: Manager inheritance
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Managers documentation says:

Managers from base classes are always inherited by the child class, using Python’s normal name resolution order (names on the child class override all others; then come names on the first parent class, and so on).

If no managers are declared on a model and/or its parents, Django automatically creates the objects manager.

For abstract base classes this works properly, inheriting the manager from the base model and therefore overriding the objects manager if so declared.
For my non-abstract inheritance example, this does not work the same way ...

class MyManager(models.Manager):
    pass


class A(models.Model):
    objects = MyManager()
    other = MyManager()


class B(A):
    pass
In [4]: B.objects.__class__
Out[4]: django.db.models.manager.Manager

In [5]: B.other.__class__
Out[5]: test_app.models.MyManager

Change History (6)

comment:1 by Simon Charette, 7 years ago

Resolution: invalid
Status: newclosed

You are using Django < 1.10 while reading the documentation for Django >= 1.10.

As the Django 1.10 documentation mentions:

In older versions, manager inheritance varied depending on the type of model inheritance (i.e. Abstract base classes, Multi-table inheritance, or Proxy models), especially with regards to electing the default manager.

comment:2 by Tim Graham, 7 years ago

Component: UncategorizedDocumentation
Resolution: invalid
Status: closednew
Summary: Manager inheritance for multi-table inheritance model behaviourManager inheritance documentation doesn't mention manager_inheritance_from_future
Triage Stage: UnreviewedAccepted

Actually, the behavior is as documented but only when using Meta.manager_inheritance_from_future=True. The documentation needs to mention this. I'll propose a patch.

comment:3 by Tim Graham, 7 years ago

Has patch: set

My PR is intentionally vague as it's difficult to tell which specific behaviors are controlled by the attribute since there were a several manager changes spread over two commits: 3a47d42fa33012b2156bf04058d933df6b3082d2 and ed0ff913c648b16c4471fc9a9441d1ee48cb5420.

comment:4 by GitHub <noreply@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 22eb15a1:

[1.11.x] Fixed #27875 -- Doc'd manager_inheritance_from_future in manager docs.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In e298ec4:

[1.10.x] Fixed #27875 -- Doc'd manager_inheritance_from_future in manager docs.

Backport of 22eb15a18c16b93496f6e88ebe3a306daad492b1 from stable/1.11.x

in reply to:  1 comment:6 by ek-init, 7 years ago

Replying to Simon Charette:

You are using Django < 1.10 while reading the documentation for Django >= 1.10.

As the Django 1.10 documentation mentions:

In older versions, manager inheritance varied depending on the type of model inheritance (i.e. Abstract base classes, Multi-table inheritance, or Proxy models), especially with regards to electing the default manager.

Fixed, but I want to mention that I was using Django 1.10.5 :)

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