diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-05-30 00:11:31 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-05-31 14:32:58 -0400 |
| commit | 53a5fb3cc0137bebeebc0d4d321dbfe20397b065 (patch) | |
| tree | aaac57d21458281d61241c70b3ed23ab7fa5a169 /tests | |
| parent | 359be1c8702ede41e7fe823ed13350795ba96a61 (diff) | |
Fixed #26676 -- Prevented prefetching to_attr from caching its result in through attr.
Thanks Ursidours for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/prefetch_related/tests.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 41eee219b8..c34682a33d 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -5,7 +5,7 @@ import warnings from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db import connection -from django.db.models import Prefetch +from django.db.models import Prefetch, QuerySet from django.db.models.query import get_prefetcher from django.test import TestCase, override_settings from django.test.utils import CaptureQueriesContext @@ -737,6 +737,12 @@ class CustomPrefetchTests(TestCase): with self.assertRaisesMessage(ValueError, 'Prefetch querysets cannot use values().'): Prefetch('houses', House.objects.values('pk')) + def test_to_attr_doesnt_cache_through_attr_as_list(self): + house = House.objects.prefetch_related( + Prefetch('rooms', queryset=Room.objects.all(), to_attr='to_rooms'), + ).get(pk=self.house3.pk) + self.assertIsInstance(house.rooms.all(), QuerySet) + class DefaultManagerTests(TestCase): @@ -1268,7 +1274,7 @@ class Ticket21760Tests(TestCase): house.save() def test_bug(self): - prefetcher = get_prefetcher(self.rooms[0], 'house')[0] + prefetcher = get_prefetcher(self.rooms[0], 'house', 'house')[0] queryset = prefetcher.get_prefetch_queryset(list(Room.objects.all()))[0] self.assertNotIn(' JOIN ', force_text(queryset.query)) |
