mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #24873 -- Prevented nested Prefetch objects from being overwritten.
This commit is contained in:
parent
06747ee790
commit
74261bc593
2 changed files with 17 additions and 1 deletions
|
@ -626,6 +626,17 @@ class CustomPrefetchTests(TestCase):
|
|||
room = Room.objects.filter(main_room_of__isnull=False).prefetch_related(Prefetch('main_room_of', queryset=houses.filter(address='DoesNotExist'), to_attr='main_room_of_attr')).first()
|
||||
self.assertIsNone(room.main_room_of_attr)
|
||||
|
||||
def test_nested_prefetch_related_are_not_overwritten(self):
|
||||
# Regression test for #24873
|
||||
houses_2 = House.objects.prefetch_related(Prefetch('rooms'))
|
||||
persons = Person.objects.prefetch_related(Prefetch('houses', queryset=houses_2))
|
||||
houses = House.objects.prefetch_related(Prefetch('occupants', queryset=persons))
|
||||
list(houses) # queryset must be evaluated once to reproduce the bug.
|
||||
self.assertEqual(
|
||||
houses.all()[0].occupants.all()[0].houses.all()[1].rooms.all()[0],
|
||||
self.room2_1
|
||||
)
|
||||
|
||||
|
||||
class DefaultManagerTests(TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue