#2256: queryset.count() does not work correctly with sliced querysets
------------------------------------+---------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Status: new | Component: Database wrapper
Version: | Resolution:
Keywords: queryset count limit | Stage: Accepted
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 1
------------------------------------+---------------------------------------
Changes (by mtredinnick):
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
Comment:
My earlier comment was that count() and limit/offset do not mix at the SQL
level. You have worked around that by manually applying those parameters
inside the Python code. I think this is counter-intuitive, since it's now
no longer SQL-intuitive or Python-intuitive (slicing the single count()
result changes the result?! We implemented limit/offset as slices because
it was analogous -- you were slicing a sequence of results). But I can see
the flip side, too, so I'm not going to veto this.
One problem with the patch is
{{{
#!python
>>> articles[8:100].count()
-1
}}}
(using the same test data setup). You need to make line 224 be something
like {{{count = max(0, count - offset)}}}. Fix that and add a test and
we're good to go, I think.
--
Ticket URL: <http://code.djangoproject.com/ticket/2256#comment:14>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---