Opened 9 years ago

Closed 9 years ago

Last modified 7 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: master
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


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 Changed 9 years ago by anonymous

Does this increase performance ?

comment:2 Changed 9 years ago by Karen Tracey

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 Changed 9 years ago by stefantalpalaru

Resolution: invalid
Status: closedreopened

You're right. My mistake.

comment:4 Changed 9 years ago by stefantalpalaru

Resolution: invalid
Status: reopenedclosed

comment:5 Changed 7 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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