diff options
author | Paulo <commonzenpython@gmail.com> | 2018-05-27 13:48:24 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-05-27 21:45:51 -0400 |
commit | 6104875a2cc797bbd1254aa61f22a9b03d652128 (patch) | |
tree | 8f5ad727468d9f352d43a774c17fb08247357eda /tests/prefetch_related | |
parent | e0ff88be4f3a40d07d94d974c64a490d2ecb3e78 (diff) | |
download | django-6104875a2cc797bbd1254aa61f22a9b03d652128.tar.gz |
Fixed #29230 -- Fixed nested prefetches that clash with descriptors.
Diffstat (limited to 'tests/prefetch_related')
-rw-r--r-- | tests/prefetch_related/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 5a701bffec..9201ff3853 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -772,6 +772,19 @@ class CustomPrefetchTests(TestCase): self.room2_1 ) + def test_nested_prefetch_related_with_duplicate_prefetcher(self): + """ + Nested prefetches whose name clashes with descriptor names + (Person.houses here) are allowed. + """ + occupants = Person.objects.prefetch_related( + Prefetch('houses', to_attr='some_attr_name'), + Prefetch('houses', queryset=House.objects.prefetch_related('main_room')), + ) + houses = House.objects.prefetch_related(Prefetch('occupants', queryset=occupants)) + with self.assertNumQueries(5): + self.traverse_qs(list(houses), [['occupants', 'houses', 'main_room']]) + def test_values_queryset(self): with self.assertRaisesMessage(ValueError, 'Prefetch querysets cannot use values().'): Prefetch('houses', House.objects.values('pk')) |