[Django] #28036: Unexpected exception raised by previous_page_number() method - Django Paginator

2 views
Skip to first unread message

Django

unread,
Apr 6, 2017, 7:21:51 AM4/6/17
to django-...@googlegroups.com
#28036: Unexpected exception raised by previous_page_number() method - Django
Paginator
-------------------------------------+-------------------------------------
Reporter: Pat | Owner: nobody
Type: | Status: new
Uncategorized |
Component: | Version: 1.10
Uncategorized | Keywords: paginator,
Severity: Normal | InvalidPage
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{
>>> objects = ['john', 'paul', 'george', 'ringo']
>>> p = Paginator(objects, 2)
>>> p.count
4
>>> p.num_pages
2
>>> page1 = p.page(1)
>>>
>>> page1.previous_page_number()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Rick\ws2\env\lib\site-packages\django\core\paginator.py",
line 136
, in previous_page_number
return self.paginator.validate_number(self.number - 1)
File "C:\Users\Rick\ws2\env\lib\site-packages\django\core\paginator.py",
line 38,
in validate_number
raise EmptyPage('That page number is less than 1')
django.core.paginator.EmptyPage: That page number is less than 1
>>>
}}}

According to the `previous_page_number()` documentation.

Returns the previous page number. Raises `InvalidPage` if previous page
doesn’t exist.

I was expecting `previous_page_number()` to raise `InvalidPage` exception
as documentation says.

--
Ticket URL: <https://code.djangoproject.com/ticket/28036>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 6, 2017, 7:23:27 AM4/6/17
to django-...@googlegroups.com
#28036: Unexpected exception raised by previous_page_number() method - Django
Paginator
-------------------------------------+-------------------------------------
Reporter: Pat | Owner: Pat
Type: Uncategorized | Status: assigned
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: paginator, | Triage Stage:
InvalidPage | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Pat):

* owner: nobody => Pat
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28036#comment:1>

Django

unread,
Apr 6, 2017, 8:34:55 AM4/6/17
to django-...@googlegroups.com
#28036: Unexpected exception raised by previous_page_number() method - Django
Paginator
-------------------------------------+-------------------------------------
Reporter: Pat | Owner: Pat
Type: Uncategorized | Status: assigned
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: paginator, | Triage Stage:
InvalidPage | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by kapil garg):

because `EmptyPage` is subclass of `InvalidPage`.

You can catch `EmptyPage` and `PageNotAnInteger` using their super class
`InvalidPage`

--
Ticket URL: <https://code.djangoproject.com/ticket/28036#comment:2>

Django

unread,
Apr 6, 2017, 8:36:04 AM4/6/17
to django-...@googlegroups.com
#28036: Unexpected exception raised by previous_page_number() method - Django
Paginator
-------------------------------------+-------------------------------------
Reporter: Pat | Owner: Pat
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution: invalid

Keywords: paginator, | Triage Stage:
InvalidPage | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kapil garg):

* status: assigned => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/28036#comment:3>

Reply all
Reply to author
Forward
0 new messages