mirror of
https://github.com/django/django.git
synced 2025-10-29 08:36:09 +00:00
Fixed #31044 -- Errored nicely when using Prefetch with a raw() queryset.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9e565386d3
commit
4540842bc3
@@ -1534,8 +1534,15 @@ class Prefetch:
|
||||
self.prefetch_through = lookup
|
||||
# `prefetch_to` is the path to the attribute that stores the result.
|
||||
self.prefetch_to = lookup
|
||||
if queryset is not None and not issubclass(queryset._iterable_class, ModelIterable):
|
||||
raise ValueError('Prefetch querysets cannot use values().')
|
||||
if queryset is not None and (
|
||||
isinstance(queryset, RawQuerySet) or (
|
||||
hasattr(queryset, '_iterable_class') and
|
||||
not issubclass(queryset._iterable_class, ModelIterable)
|
||||
)
|
||||
):
|
||||
raise ValueError(
|
||||
'Prefetch querysets cannot use raw() and values().'
|
||||
)
|
||||
if to_attr:
|
||||
self.prefetch_to = LOOKUP_SEP.join(lookup.split(LOOKUP_SEP)[:-1] + [to_attr])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user