From 69b69f6d6085d80ccf36a3e999e9e5b98d580786 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Thu, 10 Dec 2015 15:42:25 +0500 Subject: [PATCH] Fixed #25894 -- Fixed evaluation of zero-length slices of QuerySet.values(). --- django/db/models/sql/compiler.py | 2 -- docs/releases/1.9.1.txt | 3 +++ tests/queries/tests.py | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 9ebb94a6ce..a018517b89 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -363,8 +363,6 @@ class SQLCompiler(object): If 'with_limits' is False, any limit/offset information is not included in the query. """ - if with_limits and self.query.low_mark == self.query.high_mark: - return '', () self.subquery = subquery refcounts_before = self.query.alias_refcount.copy() try: diff --git a/docs/releases/1.9.1.txt b/docs/releases/1.9.1.txt index eee5a88737..520c2b3c31 100644 --- a/docs/releases/1.9.1.txt +++ b/docs/releases/1.9.1.txt @@ -37,3 +37,6 @@ Bugfixes * Prevented ``QuerySet.delete()`` from crashing on MySQL when querying across relations (:ticket`25882`). + +* Fixed evaluation of zero-length slices of ``QuerySet.values()`` + (:ticket:`25894`). diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 7c56e92998..efbd8e3f3d 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -2429,6 +2429,12 @@ class WeirdQuerysetSlicingTests(BaseQuerysetTest): def test_empty_sliced_subquery_exclude(self): 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): def test_ticket_7302(self):