diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-01-31 16:10:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-31 16:10:05 +0100 |
| commit | 38eaf2f21a2398a8dd8444f6df3723898cb5fe2a (patch) | |
| tree | be170d22deda33adef20e6c9d497a1aa98afc66a /tests/fixtures | |
| parent | d3922e9e5ad045f5408b02216a824f26a50950f0 (diff) | |
Fixed #35159 -- Fixed dumpdata crash when base querysets use prefetch_related().
Regression in 139135627650ed6aaaf4c755b82c3bd43f2b8f51
following deprecation in edbf930287cb72e9afab1f7208c24b1146b0c4ec.
Thanks Andrea F for the report.
Diffstat (limited to 'tests/fixtures')
| -rw-r--r-- | tests/fixtures/models.py | 6 | ||||
| -rw-r--r-- | tests/fixtures/tests.py | 16 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py index 37b0066d70..c87e170afc 100644 --- a/tests/fixtures/models.py +++ b/tests/fixtures/models.py @@ -101,9 +101,15 @@ class ProxySpy(Spy): proxy = True +class VisaManager(models.Manager): + def get_queryset(self): + return super().get_queryset().prefetch_related("permissions") + + class Visa(models.Model): person = models.ForeignKey(Person, models.CASCADE) permissions = models.ManyToManyField(Permission, blank=True) + objects = VisaManager() def __str__(self): return "%s %s" % ( diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 78141b25b4..bce55bc355 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -830,6 +830,22 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): ) 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): # Load fixture 4 (compressed), using format specification management.call_command("loaddata", "fixture4.json", verbosity=0) |
