Commits

Michael Manfre committed 46d8d58

Don't execute a query that is sliced to have no results. E.g. LIMIT 0

  • Participants
  • Parent commits 966df69

Comments (0)

Files changed (2)

File docs/changelog.txt

   This relies upon the ``with_col_aliases`` argument to ``SQLCompiler.as_sql`` only being ``True`` when the query 
   is a subquery, which is currently the case for all usages in Django 1.5 master. :issue:`18`
 - UPDATE statements will now return the number of rows affected, instead of -1. :issue:`19`
+- Apply fix for :djangoticket:`12192`. If QuerySet slicing would result in ``LIMIT 0``, then it shouldn't reach
+  the database because there will be no response.
 
 v1.2
 ----

File sqlserver_ado/compiler.py

                     self.query.aggregate_select[alias].sql_function = 'VARP'
 
     def as_sql(self, with_limits=True, with_col_aliases=False):
+        # Django #12192 - Don't execute any DB query when QS slicing results in limit 0
+        if with_limits and self.query.low_mark == self.query.high_mark:
+            return '', ()
+        
         self._fix_aggregates()
         
         self._using_row_number = False