Opened 6 years ago

Closed 6 years ago

Last modified 5 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: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 6 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

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

comment:2 Changed 6 years ago by Carl Meyer

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 Changed 6 years ago by Carl Meyer

Has patch: set
milestone: 1.3
Version: 1.2SVN

Changed 6 years ago by Carl Meyer

Attachment: 14366_r13962.diff added

comment:4 Changed 6 years ago by Alex Gaynor

Triage Stage: AcceptedReady for checkin

comment:5 Changed 6 years ago by Russell Keith-Magee

Looks good to me.

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

comment:6 Changed 6 years ago by Alex Gaynor

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 Changed 6 years ago by Alex Gaynor

(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 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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