Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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: UI/UX:

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.

Attachments (0)

Change History (5)

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Does this increase performance ?

comment:2 Changed 4 years ago by kmtracey

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

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

  • Resolution invalid deleted
  • Status changed from closed to reopened

You're right. My mistake.

comment:4 Changed 4 years ago by stefantalpalaru

  • Resolution set to invalid
  • Status changed from reopened to closed

comment:5 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.