ValueError('Prefetch querysets cannot use values().')
See original GitHub issueProblem
When I upgraded to version 3.0.0 I started getting the following error ValueError('Prefetch querysets cannot use values().')
Here is the full traceback:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/.virtualenvs/tcj/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/.virtualenvs/tcj/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/.virtualenvs/tcj/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/.virtualenvs/tcj/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Projects/tcj/mainsite/management/commands/cron_hook.py", line 412, in handle
getattr(CronFunctions, task_name)(*args)
File "/Projects/tcj/mainsite/management/commands/cron_hook.py", line 119, in elasticsearch_reindex
tcj_elasticsearch.reindex_listings(start_id=start_id, end_id=end_id)
File "/Projects/tcj/TCJ/services/one_offs.py", line 452, in do_func
return func(*args, **kwargs)
File "/Projects/tcj/TCJ/tcj_elasticsearch.py", line 1602, in reindex_listings
listings = BaseListing.listings.with_prefetches().using(db).indexable()\
File "/Projects/tcj/business/models/listings.py", line 419, in with_prefetches
), to_attr='active_student_responses_prefetched'),
File "/.virtualenvs/tcj/lib/python2.7/site-packages/django/db/models/query.py", line 1312, in __init__
raise ValueError('Prefetch querysets cannot use values().')
ValueError: Prefetch querysets cannot use values().
I don’t understand the error given this feature from almost a year ago.
Environment
- Django Model Utils version: 3.0.0
- Django version: 1.11.2
- Python version: 2.7.13
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Prefetch querysets cannot use raw(), values(), and values_list ...
Django: ValueError: Prefetch querysets cannot use raw(), values(), and values_list() - Stack Overflow. Stack Overflow for Teams – Start collaborating and ...
Read more >Allow Prefetch query to use .values() - Django's bug tracker
The error seems obvious: the prefetch mechanism tries to access to attributes for some reason, but it got a dict from the query,...
Read more >django.db.models.query — Parkour LIMS documentation
_iterable_class, ModelIterable): raise ValueError('Prefetch querysets cannot use values().') if to_attr: self.prefetch_to ...
Read more >django.db.models.query — Festival Grid 0.1 documentation
def __iter__(self): queryset = self.queryset db = queryset.db compiler ... ModelIterable): raise ValueError('Prefetch querysets cannot use values().
Read more >https://www.doc.ic.ac.uk/project/2012/wmproject201...
assert self.query.can_filter(), \ "Cannot use 'limit' or 'offset' with ... in the current QuerySet, setting all the given fields to the appropriate values....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think I found the issue:
InheritanceIterableshould inherit fromModelIterablenotBaseIterable. Hotpatching this works for me locally.@hanleyhansen yep I know, just highlighting the PR against the issue a little more.
This is a jazzband project, which means there are a bunch of maintainers that contribute to various projects under the jazzband umbrella. It’s my first time interacting with one though!
There are a bunch of issues and PRs open. Maybe helping out on some of the other items would help to encourage some attention on this particular issue 🤷♀️