summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-05-30 00:11:31 -0400
committerSimon Charette <charette.s@gmail.com>2016-05-31 14:35:20 -0400
commit58f0d40b6d98bf9ad2861cf742f7b2a327cc8068 (patch)
tree4005ffc452c0de196473a899a17add3bafcc38b3 /tests
parent4095317afb41588a2668e14f1223ac095d22298d (diff)
[1.10.x] Fixed #26676 -- Prevented prefetching to_attr from caching its result in through attr.
Thanks Ursidours for the report. Backport of 53a5fb3cc0137bebeebc0d4d321dbfe20397b065 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/prefetch_related/tests.py10
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))