diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-01 01:24:03 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-01 01:24:03 +0000 |
| commit | bbea457fbb523f7cae5cff52ac8227c0abf33340 (patch) | |
| tree | 97c7e54a5bc246f128fb8d0d3dd645cd2be1ecb6 | |
| parent | 5fcd75ce141b43059c722ff1f92e671d9e1a1997 (diff) | |
Fixed #10202 -- Fixed another couple of slicing edge-cases with querysets.
Patch from Alex Gaynor and Ramiro Morales.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9924 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/sql/query.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/queries/models.py | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index ac100c06e5..0f7c1b1d8a 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -345,7 +345,7 @@ class BaseQuery(object): # in SQL (in variants that provide them) doesn't change the COUNT # output. number = max(0, number - self.low_mark) - if self.high_mark: + if self.high_mark is not None: number = min(number, self.high_mark - self.low_mark) return number @@ -1760,7 +1760,7 @@ class BaseQuery(object): Typically, this means no limits or offsets have been put on the results. """ - return not (self.low_mark or self.high_mark) + return not self.low_mark and self.high_mark is None def clear_select_fields(self): """ diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index a4182c6c90..b6b7053d32 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -903,11 +903,17 @@ used in lookups. >>> Item.objects.filter(created__in=[time1, time2]) [<Item: one>, <Item: two>] -Bug #7698 -- People like to slice with '0' as the high-water mark. +Bug #7698, #10202 -- People like to slice with '0' as the high-water mark. >>> Item.objects.all()[0:0] [] >>> Item.objects.all()[0:0][:10] [] +>>> Item.objects.all()[:0].count() +0 +>>> Item.objects.all()[:0].latest('created') +Traceback (most recent call last): + ... +AssertionError: Cannot change a query once a slice has been taken. Bug #7411 - saving to db must work even with partially read result set in another cursor. |
