﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30995	Feature/docs: how should url converters decline to match for a named route?	Jack Cushman	Jack Cushman	"It is sometimes convenient to have multiple instances of a named route, where the correct one is chosen based on whether the URL converters `to_url` call succeeds. For example, the attached file has routes like this:

{{{
    path('export/foo/<foo:obj>', index, name='export'),
    path('export/bar/<bar:obj>', index, name='export'),
}}}

I then wanted to put {{{ {% url ""export"" some_foo_or_bar %} }}} in a generic export template and have the correct URL inserted.

My first attempt to do this was to raise {{{ValueError}}} in {{{to_url}}} for non-matching values, hoping that it would work the same as {{{to_python}}} where the docs specify that ""A ValueError is interpreted as no match.""

That didn't work -- nothing catches the ValueError in {{{to_url}}} -- so I found the workaround demonstrated in the attachment: if {{{to_url}}} returns an empty string (or some string that doesn't match the converter's regex), then the later regex check in {{{_reverse_with_prefix}}} will detect the non-match and everything seems to work out.

So this is either a feature request or a documentation check. I'm thinking either:

* {{{_reverse_with_prefix}}} could be updated so {{{to_url}}} works the same as {{{to_python}}}, and a {{{ValueError}}} indicates no match (which I think just means wrapping {{{try: ... except ValueError: continue}}} around the appropriate line), or
* the docs could be updated to indicate that, in {{{to_url}}}, a converter should return a non-regex-matching string such as the empty string in order to decline a match."	New feature	closed	Core (URLs)	dev	Normal	fixed	reverse, urls, converter		Ready for checkin	1	0	0	0	0	0
