#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 , 15 years ago
comment:2 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → 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:4 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Does this increase performance ?