Author: mtredinnick
Date: 2008-07-11 07:43:27 -0500 (Fri, 11 Jul 2008)
New Revision: 7885

Modified:
   django/trunk/django/db/models/sql/query.py
   django/trunk/tests/regressiontests/queries/models.py
Log:
Fixed #7698 -- Handle '0' correctly when used as the upper bound of a slice.
Based on a patch from enoksrd.


Modified: django/trunk/django/db/models/sql/query.py
===================================================================
--- django/trunk/django/db/models/sql/query.py  2008-07-11 10:03:04 UTC (rev 
7884)
+++ django/trunk/django/db/models/sql/query.py  2008-07-11 12:43:27 UTC (rev 
7885)
@@ -285,10 +285,10 @@
 
         # FIXME: Pull this out to make life easier for Oracle et al.
         if with_limits:
-            if self.high_mark:
+            if self.high_mark is not None:
                 result.append('LIMIT %d' % (self.high_mark - self.low_mark))
-            if self.low_mark:
-                if not self.high_mark:
+            if self.low_mark is not None:
+                if self.high_mark is None:
                     val = self.connection.ops.no_limit_value()
                     if val:
                         result.append('LIMIT %d' % val)
@@ -1381,12 +1381,12 @@
         constraints. So low is added to the current low value and both will be
         clamped to any existing high value.
         """
-        if high:
+        if high is not None:
             if self.high_mark:
                 self.high_mark = min(self.high_mark, self.low_mark + high)
             else:
                 self.high_mark = self.low_mark + high
-        if low:
+        if low is not None:
             if self.high_mark:
                 self.low_mark = min(self.high_mark, self.low_mark + low)
             else:

Modified: django/trunk/tests/regressiontests/queries/models.py
===================================================================
--- django/trunk/tests/regressiontests/queries/models.py        2008-07-11 
10:03:04 UTC (rev 7884)
+++ django/trunk/tests/regressiontests/queries/models.py        2008-07-11 
12:43:27 UTC (rev 7885)
@@ -810,5 +810,9 @@
 >>> Item.objects.filter(created__in=[time1, time2])
 [<Item: one>, <Item: two>]
 
+Bug #7698 -- People like to slice with '0' as the high-water mark.
+>>> Item.objects.all()[0:0]
+[]
+
 """}
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to