﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31044	Prefetch() assumes that a given queryset has an _iterable_class.	Keryn Knight	Hasan Ramezani	"Problem reported on IRC, where the exception was essentially obscuring from the user why they can't proceed...

[https://github.com/django/django/blob/c33eb6dcd0c211f8f02b2976fe3b3463f0a54498/django/db/models/query.py#L1536 The __init__ method for Prefetch] tests whether the `._iterable_class` is a subclass of `ModelIterable` in an effort to provide a runtime exception about trying to use `values()` (which is itself an oddly specific error message, because doesn't `values_list()` also return a non-ModelIterable?)

But there's at least one ostensible queryset type which one might try to use, which doesn't implement the same private API behind it's `__iter__`: `RawQuerySet` (as returned by `MyObject.objects.raw(...)`)

Attempting to use `Prefetch(""x"", queryset=MyObject.objects.raw(...))` thus raises an `AttributeError` when attempting to check whether it should raise a `ValueError` about `values()` usage.

I think it should actually test for `hasattr(queryset, ""_iterable_class"")` and raise a `TypeError` or `ValueError` about that, before trying to proceed with testing whether a specific private attribute is the correct type."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	0	0	0
