#26211: prefetch_related with Prefetch with queryset with explicit Ordering
Ignored
-------------------------------------+-------------------------------------
Reporter: cancan101 | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):
* status: new => closed
* resolution: => wontfix
Comment:
I'm also inclined to close this ticket as expected behavior.
The `prefetch_related` method stores the prefetched objects on the
instance it belongs to. As soon as you call a queryset method on the
related manager holding the cached instances (`child_set.order_by()`) a
new queryset instance is returned which doesn't hold any reference to the
previously cached results.
This is same as expecting a call to a queryset method with cached results
to perform its operation in memory instead of going back to the db.
e.g.
{{{#!python
children = Child.objects.all()
list(children) # Will issue a query and cache the results on the children
objects.
list(children) # Will reuse the cached results.
children.order_by('saved_dt') # Will perform a new database query even if
children has cached results.
}}}
If we performed the operation in memory this could lead to catastrophic
performance given a large enough result set. This would be backward
incompatible and kind of a footgun API.
I think the `Queryset` documentation makes it clear that calling a method
will create and return a new instance with no cached results.
--
Ticket URL: <https://code.djangoproject.com/ticket/26211#comment:5>
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/067.ddffd37162eeba877c93cd39d38f8113%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.