Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#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)

14366_r13962.diff (1.5 KB ) - added by Carl Meyer 13 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Alex Gaynor, 13 years ago

Triage Stage: UnreviewedAccepted

Marking as accepted because this is the first ORM bug in a while that isn't my fault.

comment:2 by Carl Meyer, 13 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 Carl Meyer, 13 years ago

Has patch: set
milestone: 1.3
Version: 1.2SVN

by Carl Meyer, 13 years ago

Attachment: 14366_r13962.diff added

comment:4 by Alex Gaynor, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Russell Keith-Magee, 13 years ago

Looks good to me.

See #14011 for what looks like a closely related ticket.

comment:6 by Alex Gaynor, 13 years ago

Resolution: fixed
Status: newclosed

(In [14084]) Fixed #14366 -- Model.objects.none().values() now correctly returns a QuerySet with no items, rather than raising an Exception. Thanks to Carl Meyer for the patch.

comment:7 by Alex Gaynor, 13 years ago

(In [14085]) [1.2.X] Fixed #14366 -- Model.objects.none().values() now correctly returns a QuerySet with no items, rather than raising an Exception. Thanks to Carl Meyer for the patch. Backport of [14084].

comment:8 by Jacob, 12 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top