Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#13035 closed (fixed)

Wrong documentation for admin and default managers

Reported by: rasca Owned by: gabrielhurley
Component: Documentation Version: master
Severity: Keywords: manager objects admin docs
Cc: rasca7@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When creating custom models managers the docs say:

If you use custom Manager objects, take note that the first Manager Django encounters (in the order in which they're defined in the model) has a special status. Django interprets this first Manager defined in a class as the "default" Manager, and several parts of Django (though not the admin application) will use that Manager exclusively for that model. As a result, it's often a good idea to be careful in your choice of default manager, in order to avoid a situation where overriding of get_query_set() results in an inability to retrieve objects you'd like to work with.

So if in a model I have

new = NewManager()
objects = models.Manager()

the admin should work as if there isn't any NewManager but it doesn't

The following works as desired:

objects = models.Manager()
new = NewManager()

Attachments (1)

13035_managers_docs_patch.diff (1.1 KB) - added by gabrielhurley 5 years ago.
Fixes some outdated information about default managers and contrib.admin

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by gabrielhurley

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to gabrielhurley
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Design decision needed

Confirmed that this behavior occurs as reported. I'm not sure which way it's *supposed* to work currently... Whether the code should be brought back in line with the docs or the docs need to be changed to reflect the code!

comment:2 Changed 5 years ago by gabrielhurley

  • Triage Stage changed from Design decision needed to Accepted

Looking at the history of tickets related to admin and _default_manager, it appears this is the intended behavior, and the docs are simply (very) outdated here. I'll add a patch to remove that "though not admin" bit.

Changed 5 years ago by gabrielhurley

Fixes some outdated information about default managers and contrib.admin

comment:3 Changed 5 years ago by gabrielhurley

  • Has patch set

comment:4 Changed 5 years ago by gabrielhurley

  • Summary changed from Wrong documentaion or bad admin behaviour to Wrong documentation for admin and default managers

comment:5 Changed 5 years ago by gabrielhurley

  • Component changed from django.contrib.admin to Documentation

This ended up being a docs bug, so I'm re-categorizing it.

comment:6 Changed 5 years ago by lukeplant

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [12930]) Fixed #13035 - Incorrect documentation regarding admin and default managers

Thanks to rasca for report and gabrielhurley for patch

comment:7 Changed 5 years ago by lukeplant

(In [12931]) [1.1.X] Fixed #13035 - Incorrect documentation regarding admin and default managers

Thanks to rasca for report and gabrielhurley for patch.

Backport of r12930 from trunk

comment:8 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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