Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12192 -- Don't execute any DB query when the QS slicing being …

…performed

will result in use of LIMIT 0. Thanks Suor for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14204 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 08d14925c9e321d7ff4e0f6c1983a74606aa1941 1 parent 5f5a61e
Ramiro Morales authored October 13, 2010
2  django/db/backends/oracle/compiler.py
@@ -27,6 +27,8 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
27 27
         If 'with_limits' is False, any limit/offset information is not
28 28
         included in the query.
29 29
         """
  30
+        if with_limits and self.query.low_mark == self.query.high_mark:
  31
+            return '', ()
30 32
 
31 33
         # The `do_offset` flag indicates whether we need to construct
32 34
         # the SQL needed to use limit/offset with Oracle.
3  django/db/models/sql/compiler.py
@@ -52,6 +52,9 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
52 52
         If 'with_limits' is False, any limit/offset information is not included
53 53
         in the query.
54 54
         """
  55
+        if with_limits and self.query.low_mark == self.query.high_mark:
  56
+            return '', ()
  57
+
55 58
         self.pre_sql_setup()
56 59
         out_cols = self.get_columns(with_col_aliases)
57 60
         ordering, ordering_group_by = self.get_ordering()
12  tests/regressiontests/queries/tests.py
@@ -86,8 +86,18 @@ class EmptyQuerySetTests(TestCase):
86 86
     def test_emptyqueryset_values(self):
87 87
         "#14366 -- calling .values() on an EmptyQuerySet and then cloning that should not cause an error"
88 88
         self.assertEqual(list(Number.objects.none().values('num').order_by('num')), [])
89  
-    
  89
+
90 90
     def test_values_subquery(self):
91 91
         self.assertQuerysetEqual(
92 92
             Number.objects.filter(pk__in=Number.objects.none().values("pk")), []
93 93
         )
  94
+
  95
+
  96
+class WeirdQuerySetSlicing(TestCase):
  97
+    def setUp(self):
  98
+        Number.objects.create(num=1)
  99
+        Number.objects.create(num=2)
  100
+
  101
+    def test_empty_resultset_sql(self):
  102
+        # ticket #12192
  103
+        self.assertNumQueries(0, lambda: list(Number.objects.all()[1:1]))

0 notes on commit 08d1492

Please sign in to comment.
Something went wrong with that request. Please try again.