Re: [Django] #32089: prefetch_related_objects() does not set the to_attr on all instances if the first instance in the list already has it.

3 views
Skip to first unread message

Django

unread,
Oct 14, 2020, 6:04:41 AM10/14/20
to django-...@googlegroups.com
#32089: prefetch_related_objects() does not set the to_attr on all instances if the
first instance in the list already has it.
-------------------------------------+-------------------------------------
Reporter: Dennis Kliban | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo
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 François Freitag):

> Our project processes instances in a stream.

Could you give more details on that? `prefetch_related_objects()` loads
all objects upfront due to
https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1546.
Even with an overloaded `__bool__`, the `QuerySet` is iterated over by
https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1585.

--
Ticket URL: <https://code.djangoproject.com/ticket/32089#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages