Opened 8 years ago

Closed 8 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: master
Severity: Keywords: QuerySet, slice
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 8 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 8 years ago.
Patched not to emit "OFFSET 0".

Download all attachments as: .zip

Change History (6)

Changed 8 years ago by enoksrd

Attachment: query.py.diff added

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

comment:1 Changed 8 years ago by Malcolm Tredinnick

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 Changed 8 years ago by Adam Vandenberg

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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'

Changed 8 years ago by Adam Vandenberg

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

Patched not to emit "OFFSET 0".

comment:3 Changed 8 years ago by Sung-jin Hong

Triage Stage: UnreviewedAccepted

comment:4 Changed 8 years ago by Malcolm Tredinnick

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