Opened 17 years ago

Closed 16 years ago

#5352 closed (fixed)

queryset doesn't honor slicing limits

Reported by: pjs@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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

Description

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)
20
>>> 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/query.py", line 155, in __getitem__
    return self._result_cache[k]
IndexError: list index out of range

Change History (4)

comment:1 by Philippe Raoult, 17 years ago

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 by Philippe Raoult, 17 years ago

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

comment:3 by Malcolm Tredinnick, 17 years ago

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 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [7477].

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