Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#14366 closed (fixed)

Model.objects.none().values(...).anything() is broken

Reported by: carljm 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 carljm 5 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 5 years ago by carljm

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 5 years ago by carljm

  • Has patch set
  • milestone set to 1.3
  • Version changed from 1.2 to SVN

Changed 5 years ago by carljm

comment:4 Changed 5 years ago by Alex

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 4 years ago by russellm

Looks good to me.

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

comment:6 Changed 4 years ago by Alex

  • Resolution set to fixed
  • Status changed from new to closed

(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 4 years ago by Alex

(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 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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