Opened 4 years ago

Closed 4 years ago

#31694 closed Cleanup/optimization (invalid)

_base_manager and related objects mismatch between docs and implementation

Reported by: Josh Owned by: nobody
Component: Documentation Version: 3.0
Severity: Normal Keywords: base_manager
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello, the docs https://docs.djangoproject.com/en/dev/topics/db/managers/#using-managers-for-related-object-access indicate that:

"By default, Django uses an instance of the Model._base_manager manager class when accessing related objects (i.e. choice.question), not the _default_manager on the related object. This is because Django needs to be able to retrieve the related object, even if it would otherwise be filtered out (and hence be inaccessible) by the default manager."

This can be seen not to be the case https://github.com/django/django/blob/master/django/db/models/fields/related_descriptors.py#L519

where we can see _base_manager is used for some descriptors (ForwardManyToOneDescriptor, ReverseOneToOneDescriptor) but _default_manager for others (ReverseManyToOneDescriptor, ManyToManyDescriptor)

This seems to be inconsistent, but maybe it is done for a reason. At the very least this inconsistency should be mentioned in the docs.

Cheers!

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Component: Database layer (models, ORM)Documentation
Resolution: invalid
Status: newclosed
Type: BugCleanup/optimization

It's already clarified in the same section:

Base managers aren’t used when querying on related models, or when accessing a one-to-many or many-to-many relationship.

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