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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Django
#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.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.d14e7b1645a0dd8bd1a282674b8593c2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Django
#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.58b8a703c1afd34202957ad00cc6504b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Django
In reply to this post by Django
#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.ad1707b2500a275f16a42f305f778dac%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.