Opened 16 years ago

Closed 13 years ago

#9195 closed Bug (fixed) should raise PageNotAnInteger when given a NoneType value

Reported by: thomas@… Owned by: nobody
Component: Documentation Version: 1.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The documentation suggests that raises PageNotAnInteger for non-integer values, however passing it None raises a TypeError. I would imagine this is a fairly common use case. If a URL optionally has a search string that specifies a page number (eg. ?page=3) you would want to pass request.GET.get('page') to However, if the request lacks the search string, page() should logically return the PageNotAnInteger exception.

>>> from django.core.paginator import Paginator
>>> objects = ['john', 'paul', 'george', 'ringo']
>>> p = Paginator(objects, 2)
<Page 1 of 2>
>>>"Pete Best")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home2/ether2/webapps/migration/lib/python2.5/django/core/", line 37, in page
    number = self.validate_number(number)
  File "/home2/ether2/webapps/migration/lib/python2.5/django/core/", line 25, in validate_number
    raise PageNotAnInteger('That page number is not an integer')
PageNotAnInteger: That page number is not an integer
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home2/ether2/webapps/migration/lib/python2.5/django/core/", line 37, in page
    number = self.validate_number(number)
  File "/home2/ether2/webapps/migration/lib/python2.5/django/core/", line 23, in validate_number
    number = int(number)
TypeError: int() argument must be a string or a number, not 'NoneType'

Change History (7)

comment:1 by Karen Tracey, 16 years ago

Triage Stage: UnreviewedDesign decision needed

I'm not sure this is such a common thing, I think it is more likely that programmers have protected against 'page' not being in the search string by specifying a sensible default on the get, e.g. request.GET.get('page', 1). Technically changing the exception raised would be backwards-incompatible (though I doubt anyone has written code that depends on this behavior...still, it's impossible to know for sure). I'd be inclined to adjust the doc instead of the code to address this.

comment:2 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 by Thejaswi Puthraya, 15 years ago

Component: UncategorizedCore framework

comment:4 by Julien Phalip, 13 years ago

Component: Core frameworkDocumentation

I agree with Karen and therefore change the component of this ticket to address this case in the documentation.

comment:5 by Gabriel Hurley, 13 years ago

Triage Stage: Design decision neededAccepted

Bumping to accepted from DDN. Correcting this in the docs is fine with me.

comment:6 by Luke Plant, 13 years ago

Severity: Normal
Type: Bug

comment:7 by Horst Gutmann <zerok@…>, 13 years ago

Easy pickings: unset
Resolution: fixed
Status: newclosed
UI/UX: unset

This was already addressed by SmileyChris in [16026] with a change to the Paginator.validate_number method which now raises a PageNotAnInteger exception on ValueError as well as on TypeError.

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