#26690: Add the option in the prefetch_related to have the prefetched results
returned as a list or as a queryset
-------------------------------------+-------------------------------------
Reporter: Ursidours | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Keywords: Prefetch
Severity: Normal | prefetch_related queryset
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
In his answer in ticket #26676, Simon Charette suggested me to open this
ticket.
Currently, the result stored by prefetch_related is by default a queryset,
unless Prefetch with to_attr is used, in which case it is a list.
According to the
[https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.Prefetch
documentation about Prefetch], this trades the flexibility offered by the
queryset for a considerable performance improvement.
I can see the rationale to have this behavior by default, but it seems to
me it would be nicer to have an option to explicitly declare whether the
results should be returned as a queryset or as a list:
1. In many cases, there is no need to chain further queries to the default
prefetch_related. By explicitly asking for a list it would then become
possible to benefit from the speed improvement.
2. Conversely, some developers may be happy to take the performance hit in
order to further refine a Prefetch with to_attr.
This could be done via an optional boolean in prefetch_related,
is_chainable or force_queryset or something like this (if left unset the
current default behavior would apply). Does that sound like a good idea?
--
Ticket URL: <https://code.djangoproject.com/ticket/26690>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.ba861edbc739a20e486f03d9b9268bd8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.