mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #31044 -- Errored nicely when using Prefetch with a raw() queryset.
This commit is contained in:
parent
9e565386d3
commit
4540842bc3
2 changed files with 16 additions and 3 deletions
|
@ -815,12 +815,18 @@ class CustomPrefetchTests(TestCase):
|
|||
self.traverse_qs(list(houses), [['occupants', 'houses', 'main_room']])
|
||||
|
||||
def test_values_queryset(self):
|
||||
with self.assertRaisesMessage(ValueError, 'Prefetch querysets cannot use values().'):
|
||||
msg = 'Prefetch querysets cannot use raw() and values().'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Prefetch('houses', House.objects.values('pk'))
|
||||
# That error doesn't affect managers with custom ModelIterable subclasses
|
||||
self.assertIs(Teacher.objects_custom.all()._iterable_class, ModelIterableSubclass)
|
||||
Prefetch('teachers', Teacher.objects_custom.all())
|
||||
|
||||
def test_raw_queryset(self):
|
||||
msg = 'Prefetch querysets cannot use raw() and values().'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Prefetch('houses', House.objects.raw('select pk from house'))
|
||||
|
||||
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'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue