#26780: Prefetch objects don't work with slices
-------------------------------------+-------------------------------------
     Reporter:  ludwik               |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  prefetch, slicing    |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by charettes):

 * type:  Bug => New feature
 * version:  1.9 => master
 * component:  Uncategorized => Database layer (models, ORM)
 * stage:  Unreviewed => Accepted


Comment:

 Tentatively accepting  but as you've noticed it would require a large
 refactor of the way prefetching is actually done.

 I could see `Category.objects.prefetch_related(Prefetch('articles',
 Article.object.order_by('-published_data')[0:3],
 to_attr='latest_articles'))` being useful but the underlying prefetch
 query would need to rely on subqueries, a feature the ORM is not good at
 for now.

 Maybe the addition of the [https://github.com/django/django/pull/6478
 Subquery] expression could help here.

--
Ticket URL: <https://code.djangoproject.com/ticket/26780#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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.2ee3c90fc24b20475d248ec3dbc8d63a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to