Opened 21 months ago

Closed 15 months ago

Last modified 7 months ago

#34331 closed New feature (fixed)

Support prefetch_related() with Queryset.aiterator()

Reported by: Barry Johnson Owned by: john-parton
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Asynchronously iterating through a QuerySet that contains a prefetch_related definition is not supported in the alpha release of 4.2, but would be a quite useful feature.

If the iterator is chunked, related objects could be prefetched in a manner much like within QuerySet.iterator(), as long as the call to prefetch_related_objects is wrapped by sync_to_async().

Change History (12)

comment:1 by Simon Charette, 21 months ago

Triage Stage: UnreviewedAccepted

comment:2 by Barry Johnson, 21 months ago

Has patch: set
Owner: changed from nobody to Barry Johnson
Status: newassigned

Added PR https://github.com/django/django/pull/16543

(There are two commits -- the second one simply changes the order of an import statement. This GitHub newbie has been unable to find the "Squash and Merge" button anywhere on the GitHub user interface, nor find any documentation that says how to reach that button.)

comment:3 by Simon Charette, 21 months ago

Needs tests: set
Patch needs improvement: set

Thanks for the patch, I left some comments about on the PR.

comment:4 by john-parton, 16 months ago

Owner: changed from Barry Johnson to john-parton

comment:5 by john-parton, 16 months ago

Open pull request here https://github.com/django/django/pull/17118

I have one basic test and the minimal change to documentation there.

comment:6 by Simon Charette, 16 months ago

Needs tests: unset
Patch needs improvement: unset

comment:7 by Mariusz Felisiak, 15 months ago

Needs documentation: set
Patch needs improvement: set

comment:8 by john-parton, 15 months ago

Updated my pull request

comment:9 by Mariusz Felisiak, 15 months ago

Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 15 months ago

Resolution: fixed
Status: assignedclosed

In fff1473:

Fixed #34331 -- Added QuerySet.aiterator() support for prefetch_related().

comment:11 by nessita <124304+nessita@…>, 7 months ago

In 36b7024:

Fixed #35392, Refs #34331 -- Allowed importing aprefetch_related_objects from django.db.models.

Thanks James Ostrander for the report and fix, and to Tim Graham and
Mariusz Felisiak for the reviews.

comment:12 by Natalia <124304+nessita@…>, 7 months ago

In ea81c9d:

[5.0.x] Fixed #35392, Refs #34331 -- Allowed importing aprefetch_related_objects from django.db.models.

Thanks James Ostrander for the report and fix, and to Tim Graham and
Mariusz Felisiak for the reviews.

Backport of 36b7024b7fc881b319a2b67876e4f72ba680d6a8 from main

Note: See TracTickets for help on using tickets.
Back to Top