#14366 closed (fixed)
Model.objects.none().values(...).anything() is broken
Reported by: | Carl Meyer | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There's a bug in the interaction of EmptyQuerySet and ValuesQuerySet; chaining .none() with .values() and then following that with any QuerySet method that causes a clone results in "AttributeError: 'ValuesQuerySet' object has no attribute 'field_names'".
(Obviously this chain is useless in the simple case, but the utility of .none() is for methods that need to return a QuerySet but in some cases should return one with no results; this can easily break in such cases if the caller of that method does further processing the returned queryset that includes .values()).
Attachments (1)
Change History (9)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
I looked around for a while to see if I could find a way to pin this on multi-db, but no luck. Turns out it's just a simple matter of EmptyQuerySet._clone() ignoring its "setup" arg instead of passing it on to QuerySet._clone(). Patch with test attached, also at http://github.com/carljm/django/compare/master...ticket_14366
comment:3 by , 14 years ago
Has patch: | set |
---|---|
milestone: | → 1.3 |
Version: | 1.2 → SVN |
by , 14 years ago
Attachment: | 14366_r13962.diff added |
---|
comment:4 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 14 years ago
Looks good to me.
See #14011 for what looks like a closely related ticket.
comment:6 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Marking as accepted because this is the first ORM bug in a while that isn't my fault.