[Django] #29008: When DEBUG is True, raising Http404 in a path converter's to_python method does not result in a technical response

19 views
Skip to first unread message

Django

unread,
Jan 11, 2018, 3:33:55 AM1/11/18
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
------------------------------------------+------------------------
Reporter: Antoine Humeau | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
This is the response I get (plain text):
{{{
A server error occurred. Please contact the administrator.
}}}

I understand a `ValueError` should be raised which tells the URL resolver
"this path does not match, try next one" but `Http404` is what came to my
mind intuitively and the error message was not very helpful.


One could also make a point that raising a `Http404` should be valid way
to tell the resolver "this is indeed the right path but the current
parameter value does not match anything so stop what you are doing and let
the handler return the 404 page (including a helpful error message when
DEBUG is True instead of the default 'Django tried these URL patterns')".

This would prove useful for example to implement a path converter that
uses `get_object_or_404`.

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

Django

unread,
Jan 11, 2018, 7:22:45 PM1/11/18
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------

Reporter: Antoine Humeau | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


Comment:

It seems that other exceptions correctly result in a technical 500
response.

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

Django

unread,
Jan 12, 2018, 3:38:34 AM1/12/18
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------

Reporter: Antoine Humeau | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------

Comment (by Antoine Humeau):

The `technical_404_response` view performs a new URL resolving (cf
https://github.com/django/django/blob/a8e492bc81fca829f5d270e2d57703c02e58701e/django/views/debug.py#L482)
which will obviously raise a new `Http404` which won't be caught as only
`Resolver404` is checked. That means the WSGI handler fails and the WSGI
server returns the previously described default error message (indeed the
error message is the default one from `wsgiref.handlers.BaseHandler`
https://docs.python.org/3.6/library/wsgiref.html#wsgiref.handlers.BaseHandler.error_body).

The solution seems to be to catch `Http404` instead of `Resolver404` in
`technical_404_response`. This will result in a technical 404 page with
the `Http404`'s displayed and will match the behaviour when `DEBUG` is
`False`.

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

Django

unread,
Sep 26, 2018, 8:17:21 AM9/26/18
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------

Reporter: Antoine Humeau | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Herbert Fortes):

* cc: Herbert Fortes (added)


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

Django

unread,
Aug 1, 2019, 12:39:07 PM8/1/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned

Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------
Changes (by Ngalim Siregar):

* owner: nobody => Ngalim Siregar
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:4>

Django

unread,
Aug 2, 2019, 9:58:21 AM8/2/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

Created [https://github.com/django/django/pull/11620 PR] , but I am not
sure how to write the tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:5>

Django

unread,
Aug 2, 2019, 11:24:54 AM8/2/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------
Changes (by Claude Paroz):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:6>

Django

unread,
Aug 3, 2019, 8:54:50 AM8/3/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_tests: 1 => 0


Comment:

I've added test to the patch, but not sure if it is correct.

--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:7>

Django

unread,
Aug 9, 2019, 3:04:34 AM8/9/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:8>

Django

unread,
Aug 9, 2019, 1:22:34 PM8/9/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


* needs_tests: 1 => 0


Comment:

I have made the requested changes; please review again

--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:9>

Django

unread,
Aug 9, 2019, 2:58:42 PM8/9/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
--------------------------------+------------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1

* version: 2.0 => master


* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:10>

Django

unread,
Aug 9, 2019, 4:49:38 PM8/9/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
-------------------------------------+-------------------------------------

Reporter: Antoine Humeau | Owner: Ngalim
| Siregar
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


* needs_tests: 1 => 0

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:11>

Django

unread,
Aug 9, 2019, 5:22:46 PM8/9/19
to django-...@googlegroups.com
#29008: When DEBUG is True, raising Http404 in a path converter's to_python method
does not result in a technical response
-------------------------------------+-------------------------------------
Reporter: Antoine Humeau | Owner: Ngalim
| Siregar
Type: Bug | Status: closed

Component: Core (URLs) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"503f60ff570df5a7b1802cbf0e2e58067c167d95" 503f60ff]:
{{{
#!CommitTicketReference repository=""
revision="503f60ff570df5a7b1802cbf0e2e58067c167d95"
Fixed #29008 -- Fixed crash of 404 debug page when URL path converter
raises Http404.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29008#comment:12>

Reply all
Reply to author
Forward
0 new messages