Commit 08d14925 authored by Ramiro Morales's avatar Ramiro Morales
Browse files

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
parent 5f5a61e7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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.
+3 −0
Original line number Diff line number Diff line
@@ -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()
+11 −1
Original line number Diff line number Diff line
@@ -91,3 +91,13 @@ class EmptyQuerySetTests(TestCase):
        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]))