Merge pull request #456 from JanBednarik/ticket_19151
Fixed #19151 -- Added missing methods to EmptyQuerySet.
This commit is contained in:
commit
6b0d93df18
|
@ -1271,6 +1271,18 @@ class EmptyQuerySet(QuerySet):
|
|||
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
|
||||
|
|
|
@ -1698,6 +1698,13 @@ class EmptyQuerySetTests(TestCase):
|
|||
[]
|
||||
)
|
||||
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue