mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #29230 -- Fixed nested prefetches that clash with descriptors.
This commit is contained in:
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user