#35317: Add the possibility to do prefetches for only a subset of instances
-------------------------------------+-------------------------------------
     Reporter:  Laurent Lyaudet      |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Laurent Lyaudet):

 TLDR : Use https://pypi.org/project/django-monkey-patches/

 Replying to [comment:4 Simon Charette]:
 > I'm not convinced we should add a feature for that given
 `prefetch_related_objects` is already
 
[https://docs.djangoproject.com/en/5.0/ref/models/querysets/#django.db.models.prefetch_related_objects
 a documented public API] that allows for this feature to be built on top
 of
 > I'd be a bit more trickier when dealing with predicates for nested
 prefetches but it's still doable.
 What do you mean by a little bit trickier ?...
 I'm using querysets with Django Rest Framework serializers.
 I find it convenient to add a static method `enhance_queryset()` in each
 model serializer that adds the needed prefetches.
 Moreover, when I have nested model serializers,
 I call recursively the methods `enhance_queryset()` of the nested model
 serializers
 in the method `enhance_queryset()` of the main model serializer.
 If you use `prefetch_related_objects()` instead, either you do not inject
 querysets in your serializers,
 or you have to deal with all of this in the __init__() method of your
 serializer.
 Moreover, you have to gather the relevant objects by hand with nested
 loops to put them in `prefetch_related_objects()`...
 whilst it is already dealed with with nested prefetches using my patch...
 I think my solution is superior, but I will not lose too much time
 arguing.
 > Just like any other non-trivial feature addition like this one I suggest
 trying to gather consensus on a general need for
 [https://docs.djangoproject.com/en/5.0/internals/contributing/bugs-and-
 features/#requesting-features this feature] on the forum and / or
 developer mailing list. From providing support over this channels in the
 past years I don't remember anyone else running into a similar issue that
 couldn't be solved with `prefetch_related_objects` directly.
 Sorry, if I do that it will split the discussion in many places;
 and frankly, I already know how are recieved most of the feature requests
 on forums/mailing lists/whatever.
 Bureaucracy is not for me.

 Replying to [comment:5 Mariusz Felisiak]:
 > I agree with Simon. The ORM is already packaged with features, so we
 generally don't add new options for things that are already possible.
 Especially for niche use cases.
 >
 > You can [https://docs.djangoproject.com/en/stable/internals/contributing
 /triaging-tickets/#closing-tickets follow triaging guidelines with regards
 to wontfix tickets] and take this to DevelopersMailingList, if you don't
 agree.
 Idem.

 I don't see any way to upvote a feature request here. It would be a nice
 way to know what dev using Django wants.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35317#comment:6>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e5ba8f3fb-ea025c48-396f-423d-b02f-64c70096bce4-000000%40eu-central-1.amazonses.com.

Reply via email to