Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#13209 closed (invalid)

the Paginator class doesn't slice self.object_list properly

Reported by: stefantalpalaru Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: Paginator pagination
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Paginator class from django.core.paginator is supposed to splice self.object_list when creating the Page object (in the page() method) so only the items on that page are retrieved.

Due to a misunderstanding of the splice syntax, more items than needed are fetched:

return Page(self.object_list[bottom:top], number, self)

where top = bottom + self.per_page

The correct code is:

return Page(self.object_list[bottom:self.per_page], number, self)

and the lines where 'top' is computed and adjusted can be removed.

Change History (5)

comment:1 by anonymous, 15 years ago

Does this increase performance ?

comment:2 by Karen Tracey, 15 years ago

Resolution: invalid
Status: newclosed

It's slice syntax, not splice, and the paginator is doing it right:

>>> lll = ['a', 'b', 'c', 'd', 'e', 'f']
>>> npp = 3
>>> top = 1
>>> bottom = top+npp
>>> lll[top:bottom]
['b', 'c', 'd']

The proposed replacement would produce the wrong answers:

>>> lll[top:npp]
['b', 'c'] # only 2 element where there should be 3
>>> top = 4
>>> lll[top:npp] # none when there should be ['e', 'f']
[]

comment:3 by stefantalpalaru, 15 years ago

Resolution: invalid
Status: closedreopened

You're right. My mistake.

comment:4 by stefantalpalaru, 15 years ago

Resolution: invalid
Status: reopenedclosed

comment:5 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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