Re: [Django] #35159: dumpdata crashes on querysets with prefetch_related(). (was: dumpdata does not work in 5.0.1 on QuerySets with prefetch_related)

4 views
Skip to first unread message

Django

unread,
Jan 30, 2024, 11:55:26 PM1/30/24
to django-...@googlegroups.com
#35159: dumpdata crashes on querysets with prefetch_related().
-------------------------------------+-------------------------------------
Reporter: Andrea F | Owner: yushan
Type: Bug | Status: assigned
Component: Core (Management | Version: 5.0
commands) |
Severity: Release blocker | Resolution:
Keywords: dumpdata chunk_size | Triage Stage: Accepted
iterator prefetch_related |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Jacob Walls, Raphael Kimmig, Simon Charette (added)
* summary: dumpdata does not work in 5.0.1 on QuerySets with
prefetch_related => dumpdata crashes on querysets with
prefetch_related().
* severity: Normal => Release blocker
* easy: 1 => 0
* stage: Unreviewed => Accepted

Comment:

Thanks for the report. Does the following patch work for you?
{{{#!diff
diff --git a/django/core/management/commands/dumpdata.py
b/django/core/management/commands/dumpdata.py
index cc183517e3..01ff8974dd 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -219,7 +219,10 @@ class Command(BaseCommand):
if count_only:
yield queryset.order_by().count()
else:
- yield from queryset.iterator()
+ chunk_size = (
+ 2000 if queryset._prefetch_related_lookups
else None
+ )
+ yield from
queryset.iterator(chunk_size=chunk_size)

try:
self.stdout.ending = None

}}}
Regression in 139135627650ed6aaaf4c755b82c3bd43f2b8f51 (#29984).
--
Ticket URL: <https://code.djangoproject.com/ticket/35159#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages