#34249 closed Cleanup/optimization (duplicate)

Custom RelatedManager documentation should have side tip on prefetch_related

Reported by: Vaughn Koch Owned by: nobody
Component: Documentation Version: 4.1
Severity: Normal Keywords: documentation relatedmanager custom prefetch_related
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This Django documentation shows how to use a custom manager for reverse relations.

https://docs.djangoproject.com/en/4.1/topics/db/queries/#using-custom-reverse-manager

In the given example, this works well as-is, but if you prefetch_related the entries when you're querying Blog, Django will use the prefetch_related cache and ignore the custom manager.

This behavior may/may not be desired, but the documentation could use a side tip about this condition, maybe in a 'Good to know' infobox.

Also, separately: one flaw in the documented approach is that you have to explicitly use the custom manager when making a query - there doesn't seem to be a way to make the custom manager the default, which can cause issues if you forget to add it to all your calls.

Change History (1)

comment:1 by Mariusz Felisiak, 22 months ago

Easy pickings: unset
Resolution: duplicate
Status: newclosed

Duplicate of #30355.

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