mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #35159 -- Fixed dumpdata crash when base querysets use prefetch_related().
Regression in1391356276
following deprecation inedbf930287
. Thanks Andrea F for the report.
This commit is contained in:
parent
d3922e9e5a
commit
38eaf2f21a
@ -219,7 +219,10 @@ class Command(BaseCommand):
|
|||||||
if count_only:
|
if count_only:
|
||||||
yield queryset.order_by().count()
|
yield queryset.order_by().count()
|
||||||
else:
|
else:
|
||||||
yield from queryset.iterator()
|
chunk_size = (
|
||||||
|
2000 if queryset._prefetch_related_lookups else None
|
||||||
|
)
|
||||||
|
yield from queryset.iterator(chunk_size=chunk_size)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.stdout.ending = None
|
self.stdout.ending = None
|
||||||
|
@ -24,3 +24,7 @@ Bugfixes
|
|||||||
``FilteredRelation()`` with querysets as right-hand sides (:ticket:`35135`).
|
``FilteredRelation()`` with querysets as right-hand sides (:ticket:`35135`).
|
||||||
``FilteredRelation()`` now raises a ``ValueError`` on querysets as right-hand
|
``FilteredRelation()`` now raises a ``ValueError`` on querysets as right-hand
|
||||||
sides.
|
sides.
|
||||||
|
|
||||||
|
* Fixed a regression in Django 5.0 that caused a crash of the ``dumpdata``
|
||||||
|
management command when a base queryset used ``prefetch_related()``
|
||||||
|
(:ticket:`35159`).
|
||||||
|
6
tests/fixtures/models.py
vendored
6
tests/fixtures/models.py
vendored
@ -101,9 +101,15 @@ class ProxySpy(Spy):
|
|||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
|
class VisaManager(models.Manager):
|
||||||
|
def get_queryset(self):
|
||||||
|
return super().get_queryset().prefetch_related("permissions")
|
||||||
|
|
||||||
|
|
||||||
class Visa(models.Model):
|
class Visa(models.Model):
|
||||||
person = models.ForeignKey(Person, models.CASCADE)
|
person = models.ForeignKey(Person, models.CASCADE)
|
||||||
permissions = models.ManyToManyField(Permission, blank=True)
|
permissions = models.ManyToManyField(Permission, blank=True)
|
||||||
|
objects = VisaManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s %s" % (
|
return "%s %s" % (
|
||||||
|
16
tests/fixtures/tests.py
vendored
16
tests/fixtures/tests.py
vendored
@ -830,6 +830,22 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(len(warning_list), 0)
|
self.assertEqual(len(warning_list), 0)
|
||||||
|
|
||||||
|
def test_dumpdata_objects_with_prefetch_related(self):
|
||||||
|
management.call_command(
|
||||||
|
"loaddata", "fixture6.json", "fixture8.json", verbosity=0
|
||||||
|
)
|
||||||
|
with self.assertNumQueries(5):
|
||||||
|
self._dumpdata_assert(
|
||||||
|
["fixtures.visa"],
|
||||||
|
'[{"fields": {"permissions": [["add_user", "auth", "user"]],'
|
||||||
|
'"person": ["Stephane Grappelli"]},'
|
||||||
|
'"model": "fixtures.visa", "pk": 2},'
|
||||||
|
'{"fields": {"permissions": [], "person": ["Prince"]},'
|
||||||
|
'"model": "fixtures.visa", "pk": 3}]',
|
||||||
|
natural_foreign_keys=True,
|
||||||
|
primary_keys="2,3",
|
||||||
|
)
|
||||||
|
|
||||||
def test_compress_format_loading(self):
|
def test_compress_format_loading(self):
|
||||||
# Load fixture 4 (compressed), using format specification
|
# Load fixture 4 (compressed), using format specification
|
||||||
management.call_command("loaddata", "fixture4.json", verbosity=0)
|
management.call_command("loaddata", "fixture4.json", verbosity=0)
|
||||||
|
Loading…
Reference in New Issue
Block a user