Opened 4 years ago

Closed 4 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: mlissner 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 mlissner 4 years ago.
Patch to fix the above issue.

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by mlissner

Patch to fix the above issue.

comment:1 Changed 4 years ago by jaylett

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by jaylett

  • Triage Stage changed from Accepted to Ready for checkin

Patch applies cleanly against master and looks good to me.

comment:3 Changed 4 years ago by claudep

  • Resolution set to invalid
  • Status changed from new to closed
  • Triage Stage changed from Ready for checkin to Unreviewed

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

  • Cc mlissner added
  • Resolution invalid deleted
  • Status changed from closed to reopened

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 4 years ago by mlissner (previous) (diff)

comment:5 Changed 4 years ago by mlissner

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

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