diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 9ebb94a6ce4..a018517b892 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 eee5a887377..520c2b3c317 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 7c56e92998e..efbd8e3f3d5 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):