I've stumbled upon this code in the main branch: (see screenshot)
The usecase is iterating through a queryset with prefetch_related lookups
specified.
Do I understand correctly that multiple database queries happen upon
fetching every chunk, and also that multiple database connections are
required?
If so, than I think it would be better just to prohibit the use of
prefetch_related with QuerySet.iterate
--
Ticket URL: <https://code.djangoproject.com/ticket/33493>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "methods_that.png" added.
* type: Uncategorized => Bug
* component: Uncategorized => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/33493#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/33493#comment:2>
* status: new => closed
* type: Bug => Cleanup/optimization
* resolution: => wontfix
Comment:
Support for prefetching related objects with `QuerySet.iterator()` was
added in edbf930287cb72e9afab1f7208c24b1146b0c4ec, and yes an extra query
is necessary for each chunk, it's documented. You can check related
discussions in the ticket #29984, on the [https://groups.google.com/g
/django-developers/c/ADgUd6jRvdw/m/_ZnETNlcAAAJ mailing list], and in
[https://github.com/django/django/pull/15334 PR]. I don't see any reason
to remove this feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/33493#comment:3>