summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2010-10-13 23:36:16 +0000
committerRamiro Morales <cramm0@gmail.com>2010-10-13 23:36:16 +0000
commit08d14925c9e321d7ff4e0f6c1983a74606aa1941 (patch)
treebd5e68ee862d063493fb08b74d2d3d408f08921d
parent5f5a61e7804beab76b92178e48cd74cae007a8ec (diff)
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
-rw-r--r--django/db/backends/oracle/compiler.py2
-rw-r--r--django/db/models/sql/compiler.py3
-rw-r--r--tests/regressiontests/queries/tests.py12
3 files changed, 16 insertions, 1 deletions
diff --git a/django/db/backends/oracle/compiler.py b/django/db/backends/oracle/compiler.py
index cc1541ff3f..c7b10429c2 100644
--- a/django/db/backends/oracle/compiler.py
+++ b/django/db/backends/oracle/compiler.py
@@ -27,6 +27,8 @@ class SQLCompiler(compiler.SQLCompiler):
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 '', ()
# The `do_offset` flag indicates whether we need to construct
# the SQL needed to use limit/offset with Oracle.
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index eaf2cd2569..a11d556b38 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -52,6 +52,9 @@ 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.pre_sql_setup()
out_cols = self.get_columns(with_col_aliases)
ordering, ordering_group_by = self.get_ordering()
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index 7d393bc2aa..795725a992 100644
--- a/tests/regressiontests/queries/tests.py
+++ b/tests/regressiontests/queries/tests.py
@@ -86,8 +86,18 @@ class EmptyQuerySetTests(TestCase):
def test_emptyqueryset_values(self):
"#14366 -- calling .values() on an EmptyQuerySet and then cloning that should not cause an error"
self.assertEqual(list(Number.objects.none().values('num').order_by('num')), [])
-
+
def test_values_subquery(self):
self.assertQuerysetEqual(
Number.objects.filter(pk__in=Number.objects.none().values("pk")), []
)
+
+
+class WeirdQuerySetSlicing(TestCase):
+ def setUp(self):
+ Number.objects.create(num=1)
+ Number.objects.create(num=2)
+
+ def test_empty_resultset_sql(self):
+ # ticket #12192
+ self.assertNumQueries(0, lambda: list(Number.objects.all()[1:1]))