Code

Opened 6 years ago

Closed 6 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 6 years ago.
svn diff of my fix against django/db/models/sql/query.py r7602
7698-no-offset-zero.patch (635 bytes) - added by adamv 6 years ago.
Patched not to emit "OFFSET 0".

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by enoksrd

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

comment:1 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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 6 years ago by adamv

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution fixed deleted
  • Status changed from closed to reopened

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 6 years ago by adamv

Patched not to emit "OFFSET 0".

comment:3 Changed 6 years ago by serialx

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.