Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed #19151 -- Added missing methods to EmptyQuerySet. #456

Merged
merged 1 commit into from

2 participants

Jan Bednařík Alex Gaynor
Jan Bednařík

Added values() and values_list() methods to EmptyQuerySet.

Jan Bednařík JanBednarik Fixed #19151 -- Added missing methods to EmptyQuerySet.
Added values() and values_list() methods to EmptyQuerySet.
b87e2f4
Alex Gaynor alex merged commit 6b0d93d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 20, 2012
  1. Jan Bednařík

    Fixed #19151 -- Added missing methods to EmptyQuerySet.

    JanBednarik authored
    Added values() and values_list() methods to EmptyQuerySet.
This page is out of date. Refresh to see the latest.
12 django/db/models/query.py
View
@@ -1271,6 +1271,18 @@ def aggregate(self, *args, **kwargs):
kwargs[arg.default_alias] = arg
return dict([(key, None) for key in kwargs])
+ def values(self, *fields):
+ """
+ Always returns EmptyQuerySet.
+ """
+ return self
+
+ def values_list(self, *fields, **kwargs):
+ """
+ Always returns EmptyQuerySet.
+ """
+ return self
+
# EmptyQuerySet is always an empty result in where-clauses (and similar
# situations).
value_annotation = False
7 tests/regressiontests/queries/tests.py
View
@@ -1698,6 +1698,13 @@ def test_values_subquery(self):
[]
)
+ def test_ticket_19151(self):
+ # #19151 -- Calling .values() or .values_list() on an EmptyQuerySet
+ # should return EmptyQuerySet and not cause an error.
+ q = EmptyQuerySet()
+ self.assertQuerysetEqual(q.values(), [])
+ self.assertQuerysetEqual(q.values_list(), [])
+
class ValuesQuerysetTests(BaseQuerysetTest):
def test_flat_values_lits(self):
Something went wrong with that request. Please try again.