[Django] #37143: aiterator() missing check for chunk_size=None after prefetch_related()

24 views
Skip to first unread message

Django

unread,
Jun 4, 2026, 12:16:32 PMJun 4
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 5.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
`aiterator()` is missing the
[https://github.com/django/django/blob/4bbc27c8686f10f9556cef02dbfa9f5157fbcf56/django/db/models/query.py#L566
check] found in `iterator()` for `chunk_size=None` after
`prefetch_related()`:

`iterator()` version:
{{{#!py
if chunk_size is None:
if self._prefetch_related_lookups:
raise ValueError(
"chunk_size must be provided when using
QuerySet.iterator() after "
"prefetch_related()."
)
}}}

I think this should have been implemented in #34331.

The rationale for the check was to alert users that the number of queries
could spike with small batch sizes, which you might be tempted to minimize
if prioritizing memory optimizations.
--
Ticket URL: <https://code.djangoproject.com/ticket/37143>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 4, 2026, 10:47:49 PMJun 4
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by zky):

* owner: (none) => zky
* stage: Unreviewed => Accepted
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:1>

Django

unread,
Jun 6, 2026, 1:13:00 PMJun 6
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by zky):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:2>

Django

unread,
Jun 7, 2026, 1:19:17 AMJun 7
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by zky):

https://github.com/django/django/pull/21425
--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:3>

Django

unread,
Jun 11, 2026, 10:56:28 AMJun 11
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* cc: Simon Charette (added)
* needs_better_patch: 0 => 1
* needs_docs: 0 => 1

Comment:

Needs a release note, and now that I think of it, probably a deprecation
path as well given that we accidentally supported this.
--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:4>

Django

unread,
Jun 11, 2026, 9:39:36 PMJun 11
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by zky):

Replying to [comment:4 Jacob Walls]:
> Needs a release note, and now that I think of it, probably a deprecation
path as well given that we accidentally supported this.
I have changed the behavior from raising an exception to issuing a
deprecation warning.
--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:5>

Django

unread,
Jun 11, 2026, 9:39:57 PMJun 11
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by zky):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:6>

Django

unread,
Jun 15, 2026, 5:01:37 PM (12 days ago) Jun 15
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:7>

Django

unread,
Jun 17, 2026, 9:10:06 AM (10 days ago) Jun 17
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by zky):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:8>

Django

unread,
Jun 17, 2026, 2:02:08 PM (10 days ago) Jun 17
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_docs: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:9>

Django

unread,
Jun 18, 2026, 10:40:53 AM (9 days ago) Jun 18
to django-...@googlegroups.com
#37143: aiterator() missing check for chunk_size=None after prefetch_related()
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: zky
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"ca5746b8680a5e7e14014d365c0610f825df1dae" ca5746b]:
{{{#!CommitTicketReference repository=""
revision="ca5746b8680a5e7e14014d365c0610f825df1dae"
Fixed #37143 -- Added missing chunk_size=None check to
QuerySet.aiterator().

Co-authored-by: Jacob Walls <jacobty...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37143#comment:10>
Reply all
Reply to author
Forward
0 new messages