Opened 16 years ago

Closed 16 years ago

#7698 closed (fixed)

QuerySet slices broken in corner case: QuerySet[0:0] => QuerySet[0:]

Reported by: enoksrd Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: QuerySet, slice
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you have a QuerySet and slice with an upper bound ("end") of 0 it's treated like no upper bound at all. See attached svn diff for a fix. To reproduce: let q be a QuerySet, the q[0:0] is *all* the objects in the set. Problem due to 0 being false in Python.

Attachments (2)

query.py.diff (1.4 KB ) - added by enoksrd 16 years ago.
svn diff of my fix against django/db/models/sql/query.py r7602
7698-no-offset-zero.patch (635 bytes ) - added by Adam Vandenberg 16 years ago.
Patched not to emit "OFFSET 0".

Download all attachments as: .zip

Change History (6)

by enoksrd, 16 years ago

Attachment: query.py.diff added

svn diff of my fix against django/db/models/sql/query.py r7602

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7885]) Fixed #7698 -- Handle '0' correctly when used as the upper bound of a slice.
Based on a patch from enoksrd.

comment:2 by Adam Vandenberg, 16 years ago

Resolution: fixed
Status: closedreopened

This fix appears to be adding extraneous "OFFSET 0" to the ends of non-sliced queries:

sql:

'SELECT [django_session].[session_key], [django_session].[session_data], [django_session].[expire_date] FROM [django_session] WHERE ([django_session].[session_key] = %s AND [django_session].[expire_date] > %s ) OFFSET 0'

by Adam Vandenberg, 16 years ago

Attachment: 7698-no-offset-zero.patch added

Patched not to emit "OFFSET 0".

comment:3 by Sung-jin Hong, 16 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: reopenedclosed

(In [7901]) Fixed a bozo bug from [7885]. Fixed #7698.

Note: See TracTickets for help on using tickets.
Back to Top