Code

Opened 8 years ago

Closed 8 years ago

#2878 closed defect (fixed)

Paginator last_on_page fails when .hits hasn't been called

Reported by: sago Owned by: adrian
Component: Core (Other) Version: master
Severity: normal Keywords: paginator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Because the last_on_page method relies on self._hits, it crashes when self._hits hasn't been set up yet.

This probably hasn't been seen before because most people call paginator.hits (which sets the ._hits attribute) before calling last_on_page.

All that's needed is to make sure ._hits is valid before proceeding. Calls to ._hits could be
exchanged for calls to .hits, but that would involve multiple calls to the property (and therefore the checking logic) in one go. Better, IMHO, to call self.hits once, then use the value throughout the method.

Patch shows this.

Attachments (1)

hit_bugfix.patch (955 bytes) - added by anonymous 8 years ago.

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by anonymous

comment:1 Changed 8 years ago by SmileyChris

Or someone could just apply #2575 which will fix this. However, I won't mark as a dupe because this is fixing a specific problem whereas my one adds some extra functionality as well.

comment:2 Changed 8 years ago by sago

Agreed, my vote would be to upgrade the paginator generally. Chris, your patch does that to a large extent.

My patch is a minimal fix.

Maybe we should start a thread on django.users about the requirements for the paginator, and collaborate on a general solution that would help everyone. My requirements may be slightly different from yours, etc. Then we can remove all paginator patches (there are a handful) and submit a canonical solution.

comment:3 Changed 8 years ago by SmileyChris

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

I'm pretty sure this has been fixed now #2575 has been applied. If you still can identify a problem, please re-open.

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.