Opened 8 years ago

Closed 7 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: UI/UX:

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

  • Component changed from Uncategorized to Database wrapper
  • Keywords qs-rf added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Initial queryset index is invalid in 0.96 to Initial queryset index is invalid
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 0.96 to SVN

OP mentionned 0.96 but this still happens in trunk.

comment:2 Changed 8 years ago by PhiR

  • Summary changed from Initial queryset index is invalid to queryset doesn't honor slicing limits

comment:3 Changed 8 years ago by mtredinnick

  • 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 7 years ago by mtredinnick

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

Fixed in [7477].

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