Author: mtredinnick
Date: 2009-02-28 19:35:36 -0600 (Sat, 28 Feb 2009)
New Revision: 9925

Modified:
   django/branches/releases/1.0.X/django/db/models/sql/query.py
   django/branches/releases/1.0.X/tests/regressiontests/queries/models.py
Log:
[1.0.X] Fixed #10202 -- Fixed another couple of slicing edge-cases with 
querysets.

Patch from Alex Gaynor and Ramiro Morales.

Backport of r9924 from trunk.

Modified: django/branches/releases/1.0.X/django/db/models/sql/query.py
===================================================================
--- django/branches/releases/1.0.X/django/db/models/sql/query.py        
2009-03-01 01:24:03 UTC (rev 9924)
+++ django/branches/releases/1.0.X/django/db/models/sql/query.py        
2009-03-01 01:35:36 UTC (rev 9925)
@@ -240,7 +240,7 @@
         # 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
@@ -1534,7 +1534,7 @@
 
         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):
         """

Modified: django/branches/releases/1.0.X/tests/regressiontests/queries/models.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/queries/models.py      
2009-03-01 01:24:03 UTC (rev 9924)
+++ django/branches/releases/1.0.X/tests/regressiontests/queries/models.py      
2009-03-01 01:35:36 UTC (rev 9925)
@@ -902,11 +902,17 @@
 >>> 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.


--~--~---------~--~----~------------~-------~--~----~
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