mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #26916 -- Fixed prefetch_related when using a cached_property as to_attr.
Thanks Trac alias karyon for the report and Tim for the review.
This commit is contained in:
@@ -743,6 +743,17 @@ class CustomPrefetchTests(TestCase):
|
||||
).get(pk=self.house3.pk)
|
||||
self.assertIsInstance(house.rooms.all(), QuerySet)
|
||||
|
||||
def test_to_attr_cached_property(self):
|
||||
persons = Person.objects.prefetch_related(
|
||||
Prefetch('houses', House.objects.all(), to_attr='cached_all_houses'),
|
||||
)
|
||||
for person in persons:
|
||||
# To bypass caching at the related descriptor level, don't use
|
||||
# person.houses.all() here.
|
||||
all_houses = list(House.objects.filter(occupants=person))
|
||||
with self.assertNumQueries(0):
|
||||
self.assertEqual(person.cached_all_houses, all_houses)
|
||||
|
||||
|
||||
class DefaultManagerTests(TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user