[Django] #34249: Custom RelatedManager documentation should have side tip on prefetch_related

1 view
Skip to first unread message

Django

unread,
Jan 10, 2023, 1:03:42 PM1/10/23
to django-...@googlegroups.com
#34249: Custom RelatedManager documentation should have side tip on
prefetch_related
-------------------------------------+-------------------------------------
Reporter: Vaughn | Owner: nobody
Koch |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 4.1
Documentation | Keywords: documentation
Severity: Normal | relatedmanager custom
Triage Stage: | prefetch_related
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34249>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 10, 2023, 11:49:46 PM1/10/23
to django-...@googlegroups.com
#34249: Custom RelatedManager documentation should have side tip on
prefetch_related
-------------------------------------+-------------------------------------
Reporter: Vaughn Koch | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 4.1
Severity: Normal | Resolution: duplicate
Keywords: documentation | Triage Stage:
relatedmanager custom | Unreviewed
prefetch_related |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate
* easy: 1 => 0


Comment:

Duplicate of #30355.

--
Ticket URL: <https://code.djangoproject.com/ticket/34249#comment:1>

Reply all
Reply to author
Forward
0 new messages