diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-12-09 12:55:12 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-12-09 15:45:18 +0100 |
| commit | 4540842bc385a60cf32970a8b372b80d47704bca (patch) | |
| tree | 954198e362859950eb0d0679690859728de979bc /django | |
| parent | 9e565386d3fafc8cc15d07095e50d574e5f53802 (diff) | |
Fixed #31044 -- Errored nicely when using Prefetch with a raw() queryset.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 73991df7bb..764d3ea289 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -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]) |
