Opened 11 years ago

Closed 11 years ago

#5352 closed (fixed)

queryset doesn't honor slicing limits

Reported by: pjs@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I noticed this issue today when slicing a query set.

>>> mylist = UserProfile.objects.all()[:20]
>>> mylist[20]   # Should raise index error
<UserProfile: UserProfile object>
>>> mylist[2055]
<UserProfile: UserProfile object>
>>> len(mylist)
>>> mylist[20]   # Only raises IndexError after I call len() on the queryset
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.5/site-packages/django/db/models/", line 155, in __getitem__
    return self._result_cache[k]
IndexError: list index out of range

Change History (4)

comment:1 Changed 11 years ago by Philippe Raoult

Component: UncategorizedDatabase wrapper
Keywords: qs-rf added
Summary: Initial queryset index is invalid in 0.96Initial queryset index is invalid
Triage Stage: UnreviewedAccepted
Version: 0.96SVN

OP mentionned 0.96 but this still happens in trunk.

comment:2 Changed 11 years ago by Philippe Raoult

Summary: Initial queryset index is invalidqueryset doesn't honor slicing limits

comment:3 Changed 11 years ago by Malcolm Tredinnick

Keywords: qs-rf-fixed added; qs-rf removed

The slightly different way we handle __getitem__ in the queryset-refactor branch have fixed this on the branch. The ticket will be closed when the branch is merged.

comment:4 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

Fixed in [7477].

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