Opened 12 years ago
Closed 12 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 |
Description
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)
Change History (6)
by , 12 years ago
Attachment: | 18421.diff added |
---|
comment:1 by , 12 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Patch applies cleanly against master and looks good to me.
comment:3 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Triage Stage: | Ready for checkin → Unreviewed |
If 'page' is not provided in the request, the page variable will be None. Then paginator.page will raise PageNotAnInteger which will lead to the paginator.page(1) code path. Same scenario if page is set to anything other than a integer.
comment:4 by , 12 years ago
Cc: | added |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
I'm probably about to put my foot square in my mouth, but claudep, when None is passed to Paginator.page, 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 contacts = paginator.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?
comment:5 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Scratch that. I just dug into the pagination code...this is already fixed in 1.4. Just broken in 1.3, apparently.
Patch to fix the above issue.