Browse files

Fixed #19151 -- Added missing methods to EmptyQuerySet.

Added values() and values_list() methods to EmptyQuerySet.
  • Loading branch information...
1 parent d7c6a57 commit b87e2f46c80d15abcda0e181ab894fb938ceb12f @JanBednarik JanBednarik committed Oct 21, 2012
Showing with 19 additions and 0 deletions.
  1. +12 −0 django/db/models/query.py
  2. +7 −0 tests/regressiontests/queries/tests.py
View
12 django/db/models/query.py
@@ -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
View
7 tests/regressiontests/queries/tests.py
@@ -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):

0 comments on commit b87e2f4

Please sign in to comment.