diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 7944d0358f..0cacb7f3ed 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -285,10 +285,10 @@ class Query(object): # 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 @@ class Query(object): 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: diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 272e28ff84..fe378a57b2 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -810,5 +810,9 @@ used in lookups. >>> Item.objects.filter(created__in=[time1, time2]) [, ] +Bug #7698 -- People like to slice with '0' as the high-water mark. +>>> Item.objects.all()[0:0] +[] + """}