We should check the signatures of these handler functions with a django
check (i.e. that they accept 1 or 2 arguments, depending on which one they
are) in order to prevent this happening to others.
--
Ticket URL: <https://code.djangoproject.com/ticket/29642>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* version: 2.1 => master
* stage: Unreviewed => Accepted
Comment:
Yes. That seems more than reasonable.
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:1>
Comment (by Tim Graham):
I'm not immediately convinced. These "simple checks" often turn out to be
more complicated than they seem. Didn't you write some tests for your
custom views? ;-)
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:2>
Comment (by Carlton Gibson):
It’s also about what our ‘’Average User™’’ might do. Yes, Adam should
write tests, but I can easily see people putting a handler in place and
never really trying it out.
> The feedback loop for this failure is pretty long as these only get hit
when DEBUG=False and not during tests.
This is the bit that convinced me. You write an error handler, and then
realise that it’s not straitforwardly testable, with the test client etc.
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:3>
Comment (by Tim Graham):
Maybe a documentation suggestion to facilitate testing would be helpful:
{{{
if settings.DEBUG:
urlpatterns += [
path('500/', 'path.to.custom_500_handler'),
)
}}}
I think it's more empowering than "check the signature and assume the rest
of the view works." ;-)
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:4>
Comment (by Carlton Gibson):
Yep. I can see that.
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:5>
* owner: nobody => Adam (Chainz) Johnson
* status: new => assigned
Comment:
> Maybe a documentation suggestion to facilitate testing would be helpful
I did this for my initial unit tests, it only half helps since then
`exception` isn't passed. So a view which only takes one argument would
work with such a test view.
In fact the better way to test handlers is like django's test suite for
them, with other views that raise exceptions:
https://github.com/django/django/blob/master/tests/handlers/tests_custom_error_handlers.py#L23
> These "simple checks" often turn out to be more complicated than they
seem. Didn't you write some tests for your custom views? ;-)
That's the worst thing here, I did, and they were wrong. So there was a
double loop.
The check is actually quite simple and I have a draft implementation. Also
there was no check before that the given paths are genuine so this will
add defence to two different potential failures, for each of the 4
handlers.
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:6>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10373 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"245c36d7b6934fb0ca50eed2414253f4793f1ff5" 245c36d7]:
{{{
#!CommitTicketReference repository=""
revision="245c36d7b6934fb0ca50eed2414253f4793f1ff5"
Fixed #29642 -- Added check for arguments of custom error handler views.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29642#comment:8>