Opened 12 years ago

Closed 11 years ago

#18421 closed Bug (invalid)

Pagination documentation contains error when no GET request provided

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Mike Lissner Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


The current Pagination documentation contains:

page = request.GET.get('page')

This should instead be:

page = request.GET.get('page', 1)

or else, it fails when no GET parameter is provided, which is unfortunate.

I'll attach a patch momentarily.

Attachments (1)

18421.diff (557 bytes) - added by Mike Lissner 12 years ago.
Patch to fix the above issue.

Download all attachments as: .zip

Change History (6)

Changed 12 years ago by Mike Lissner

Attachment: 18421.diff added

Patch to fix the above issue.

comment:1 Changed 11 years ago by James Aylett

Easy pickings: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 11 years ago by James Aylett

Triage Stage: AcceptedReady for checkin

Patch applies cleanly against master and looks good to me.

comment:3 Changed 11 years ago by Claude Paroz

Resolution: invalid
Status: newclosed
Triage Stage: Ready for checkinUnreviewed

If 'page' is not provided in the request, the page variable will be None. Then will raise PageNotAnInteger which will lead to the code path. Same scenario if page is set to anything other than a integer.

comment:4 Changed 11 years ago by Mike Lissner

Cc: Mike Lissner added
Resolution: invalid
Status: closedreopened

I'm probably about to put my foot square in my mouth, but claudep, when None is passed to, it throws a TypeError, not a PageNotAnInteger error:

In [1]: from django.core.paginator import Paginator
In [2]: Paginator([], 25).page(None)
TypeError                                 Traceback (most recent call last)
/var/www/court-listener/alert/<ipython-input-8-d36a5c4802f6> in <module>()
----> 1 Paginator([], 25).page(None)

/usr/lib/python2.7/dist-packages/django/core/paginator.pyc in page(self, number)
     35     def page(self, number):
     36         "Returns a Page object for the given 1-based page number."
---> 37         number = self.validate_number(number)
     38         bottom = (number - 1) * self.per_page
     39         top = bottom + self.per_page

/usr/lib/python2.7/dist-packages/django/core/paginator.pyc in validate_number(self, number)
     21         "Validates the given 1-based page number."
     22         try:
---> 23             number = int(number)
     24         except ValueError:
     25             raise PageNotAnInteger('That page number is not an integer')

TypeError: int() argument must be a string or a number, not 'NoneType'

So is it possible that the bug is actually in the Paginator code, that it should be catching this TypeError and throwing a PageNotAnInteger error instead of a TypeError?

Last edited 11 years ago by Mike Lissner (previous) (diff)

comment:5 Changed 11 years ago by Mike Lissner

Resolution: invalid
Status: reopenedclosed

Scratch that. I just dug into the pagination code...this is already fixed in 1.4. Just broken in 1.3, apparently.

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