diff --git a/django/db/models/query.py b/django/db/models/query.py
index 41c24c7..9cadbf0 100644
a
|
b
|
class ValuesQuerySet(QuerySet):
|
1027 | 1027 | |
1028 | 1028 | def _as_sql(self, connection): |
1029 | 1029 | """ |
1030 | | For ValueQuerySet (and subclasses like ValuesListQuerySet), they can |
| 1030 | For ValuesQuerySet (and subclasses like ValuesListQuerySet), they can |
1031 | 1031 | only be used as nested queries if they're already set up to select only |
1032 | 1032 | a single field (in which case, that is the field column that is |
1033 | 1033 | returned). This differs from QuerySet.as_sql(), where the column to |
… |
… |
class EmptyQuerySet(QuerySet):
|
1233 | 1233 | kwargs[arg.default_alias] = arg |
1234 | 1234 | return dict([(key, None) for key in kwargs]) |
1235 | 1235 | |
| 1236 | def values(self, *args): |
| 1237 | """ |
| 1238 | Technically, this should return an EmptyValuesQuerySet (a subclass |
| 1239 | of both this and ValuesQuerySet classes). However, we return just |
| 1240 | EmptyQuerySet. |
| 1241 | """ |
| 1242 | return self |
| 1243 | |
| 1244 | def values_list(self, *args, **kwargs): |
| 1245 | """ |
| 1246 | Similarly to above, this should return an EmptyValuesListQuerySet. |
| 1247 | However, this returns just EmptyQuerySet. |
| 1248 | """ |
| 1249 | return self |
| 1250 | |
1236 | 1251 | # EmptyQuerySet is always an empty result in where-clauses (and similar |
1237 | 1252 | # situations). |
1238 | 1253 | value_annotation = False |
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index ded3e8f..82e083d 100644
a
|
b
|
class CloneTests(TestCase):
|
1612 | 1612 | |
1613 | 1613 | |
1614 | 1614 | class EmptyQuerySetTests(TestCase): |
| 1615 | def setUp(self): |
| 1616 | # Addition for ticket #17712: have actually some data in the numbers |
| 1617 | # table, so that the below tests could return something. |
| 1618 | Number.objects.create(num=1) |
| 1619 | |
1615 | 1620 | def test_emptyqueryset_values(self): |
1616 | 1621 | # #14366 -- Calling .values() on an EmptyQuerySet and then cloning that |
1617 | 1622 | # should not cause an error" |
1618 | 1623 | self.assertQuerysetEqual( |
1619 | 1624 | Number.objects.none().values('num').order_by('num'), [] |
1620 | 1625 | ) |
| 1626 | |
| 1627 | def test_emptyqueryset_values_empty(self): |
| 1628 | # #17712 none().values() / .none().values_list() should not return |
| 1629 | # anything |
| 1630 | self.assertQuerysetEqual( |
| 1631 | Number.objects.none().values('num'), [] |
| 1632 | ) |
| 1633 | self.assertQuerysetEqual( |
| 1634 | Number.objects.none().values_list('num'), [] |
| 1635 | ) |
1621 | 1636 | |
1622 | 1637 | def test_values_subquery(self): |
1623 | 1638 | self.assertQuerysetEqual( |