Fixed #25894 -- Fixed evaluation of zero-length slices of QuerySet.values().

This commit is contained in:
Sergey Fedoseev 2015-12-10 15:42:25 +05:00 committed by Tim Graham
parent 423b3afce4
commit 69b69f6d60
3 changed files with 9 additions and 2 deletions

View File

@ -363,8 +363,6 @@ class SQLCompiler(object):
If 'with_limits' is False, any limit/offset information is not included If 'with_limits' is False, any limit/offset information is not included
in the query. in the query.
""" """
if with_limits and self.query.low_mark == self.query.high_mark:
return '', ()
self.subquery = subquery self.subquery = subquery
refcounts_before = self.query.alias_refcount.copy() refcounts_before = self.query.alias_refcount.copy()
try: try:

View File

@ -37,3 +37,6 @@ Bugfixes
* Prevented ``QuerySet.delete()`` from crashing on MySQL when querying across * Prevented ``QuerySet.delete()`` from crashing on MySQL when querying across
relations (:ticket`25882`). relations (:ticket`25882`).
* Fixed evaluation of zero-length slices of ``QuerySet.values()``
(:ticket:`25894`).

View File

@ -2429,6 +2429,12 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest):
def test_empty_sliced_subquery_exclude(self): def test_empty_sliced_subquery_exclude(self):
self.assertEqual(Eaten.objects.exclude(food__in=Food.objects.all()[0:0]).count(), 1) self.assertEqual(Eaten.objects.exclude(food__in=Food.objects.all()[0:0]).count(), 1)
def test_zero_length_values_slicing(self):
n = 42
with self.assertNumQueries(0):
self.assertQuerysetEqual(Article.objects.values()[n:n], [])
self.assertQuerysetEqual(Article.objects.values_list()[n:n], [])
class EscapingTests(TestCase): class EscapingTests(TestCase):
def test_ticket_7302(self): def test_ticket_7302(self):