#31044 closed Cleanup/optimization (fixed)
Prefetch() assumes that a given queryset has an _iterable_class.
Reported by: | Keryn Knight | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Problem reported on IRC, where the exception was essentially obscuring from the user why they can't proceed...
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.
Change History (8)
comment:1 by , 5 years ago
Summary: | Prefetch objects assume a given queryset will have an _iterable_class, so that an exception can be raised for usage of .values() → Prefetch() assumes that a given queryset has an _iterable_class. |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 2.2 → master |
comment:2 by , 5 years ago
comment:3 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 5 years ago
Patch needs improvement: | set |
---|
comment:6 by , 5 years ago
Patch needs improvement: | unset |
---|
Regression in [7ec330eeb96d0]