Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #7698 -- Handle '0' correctly when used as the upper bound of a…

… slice.

Based on a patch from enoksrd.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2b193f6100c571d4b5bc87815c7569179db27030 1 parent 88c17b5
@malcolmt malcolmt authored
View
10 django/db/models/sql/query.py
@@ -285,10 +285,10 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
# 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 @@ def set_limits(self, low=None, high=None):
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:
View
4 tests/regressiontests/queries/models.py
@@ -810,5 +810,9 @@ class Related(models.Model):
>>> 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]
+[]
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.