RedirectView failing silently on NoReverseMatch is confusing

92 views
Skip to first unread message

Grzegorz Tężycki

unread,
Jan 19, 2017, 7:17:49 AM1/19/17
to Django developers (Contributions to Django itself)
Hi everyone.

Tim Graham told me that problem with ticet: #26911 should be discuss on mailing list.
Details of ticket are here : https://code.djangoproject.com/ticket/26911

When developer set 'pattern_name' in RedirectView and this pattern is incorrect, then method catch NoReverseMatch exception and return None.

I think, that method get_redirect_url should raise ImproperlyConfigured error with message "Reverse for 'xxxx' not found.", or NoReverseMatch exception not should be catch.

What you think about this

jorr...@gmail.com

unread,
Jan 19, 2017, 8:33:39 AM1/19/17
to Django developers (Contributions to Django itself)
Raising an error definitely seems a lot more intuitive.

Alasdair Nicol

unread,
Jan 19, 2017, 8:56:50 AM1/19/17
to Django developers (Contributions to Django itself)
On Thursday, 19 January 2017 12:17:49 UTC, Grzegorz Tężycki wrote:
I think, that method get_redirect_url should raise ImproperlyConfigured error with message "Reverse for 'xxxx' not found.", or NoReverseMatch exception not should be catch.

I would prefer to stop catching NoReverseMatch, rather than raising ImproperlyConfigured. I think that

RedirectView(pattern_name='view-does-not-exist').as_view()

should have the same behaviour as 

RedirectView(url=reverse_lazy('view-does-not-exist')).as_view()

Adam Johnson

unread,
Jan 19, 2017, 4:07:44 PM1/19/17
to django-d...@googlegroups.com
I can't see any rationale for it on the ticket, PR, or mailing list discussion. The original implementation in the PR actually raised if settings.DEBUG:

if settings.DEBUG:
    raise
else:
    return None

But this was removed in merging by Marc.

I'm +1 on removing the try/except because I think broken things should fail obviously.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/004e6f3e-e750-47dd-8469-baf799933fe0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Adam

Tobias McNulty

unread,
Jan 19, 2017, 10:27:10 PM1/19/17
to django-developers
On Thu, Jan 19, 2017 at 4:07 PM, Adam Johnson <m...@adamj.eu> wrote:
I'm +1 on removing the try/except because I think broken things should fail obviously.

Another +1. I have little patience for except statements that hide errors I might care about, and this seems like one of those cases.

Tobias
--

Tobias McNulty
Chief Executive Officer

tob...@caktusgroup.com
www.caktusgroup.com

Reply all
Reply to author
Forward
0 new messages