#35442: N+1 queries from RelatedManager + only("pk")
-------------------------------------+-------------------------------------
     Reporter:  REGNIER Guillaume    |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

 This relates to #20927, #18177, and at least another ticket that asked for
 `"company_id"` to be implicitly included in the `only` call that I just
 can't find anymore.

 I think we should try to resolve that in a different way and a potential
 solution could be something like

 {{{#!python
 diff --git a/django/db/models/query.py b/django/db/models/query.py
 index cb5c63c0d1..9390d2242d 100644
 --- a/django/db/models/query.py
 +++ b/django/db/models/query.py
 @@ -119,6 +119,7 @@ def __iter__(self):
                  ),
              )
              for field, related_objs in
 queryset._known_related_objects.items()
 +            # if not is_deferred(field)
          ]
          for row in compiler.results_iter(results):
              obj = model_cls.from_db(
 }}}

 But in order to work properly it would require a refactor of
 `known_related_objects` as the current approach is naive wrt/ to how it
 namespace related objects by field as the same model field can be included
 multiple times in the the same queryset (e.g. see #35356)
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35442#comment:1>
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/0107018f63adc022-faad0d75-4b48-446a-93b8-826fe747304b-000000%40eu-central-1.amazonses.com.

Reply via email to