Skip to content

Commit

Permalink
Fixed #29775 -- Fixed URL converters in a nested namespaced path.
Browse files Browse the repository at this point in the history
When using include() without namespaces of some urlpatterns that
have an include() with namespace, the converters of the parent
include() weren't being used to convert the arguments of reverse().
  • Loading branch information
ericbrandwein authored and timgraham committed Oct 4, 2018
1 parent b8b1d8c commit b0b4aac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ answer newbie questions, and generally made Django that much better:
enlight
Enrico <[email protected]>
Eric Boersma <[email protected]>
Eric Brandwein <[email protected]>
Eric Floehr <[email protected]>
Eric Florenzano <[email protected]>
Eric Holscher <http://ericholscher.com>
Expand Down
2 changes: 2 additions & 0 deletions django/urls/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ def _populate(self):
)
)
for namespace, (prefix, sub_pattern) in url_pattern.namespace_dict.items():
current_converters = url_pattern.pattern.converters
sub_pattern.pattern.converters.update(current_converters)
namespaces[namespace] = (p_pattern + prefix, sub_pattern)
for app_name, namespace_list in url_pattern.app_dict.items():
apps.setdefault(app_name, []).extend(namespace_list)
Expand Down
8 changes: 8 additions & 0 deletions tests/urlpatterns/path_base64_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

register_converter(converters.Base64Converter, 'base64')

subsubpatterns = [
path('<base64:last_value>/', views.empty_view, name='subsubpattern-base64'),
]

subpatterns = [
path('<base64:value>/', views.empty_view, name='subpattern-base64'),
path(
'<base64:value>/',
include((subsubpatterns, 'second-layer-namespaced-base64'), 'instance-ns-base64')
),
]

urlpatterns = [
Expand Down
7 changes: 7 additions & 0 deletions tests/urlpatterns/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def test_converter_reverse(self):
url = reverse(url_name, kwargs=kwargs)
self.assertEqual(url, expected)

@override_settings(ROOT_URLCONF='urlpatterns.path_base64_urls')
def test_converter_reverse_with_second_layer_instance_namespace(self):
kwargs = included_kwargs.copy()
kwargs['last_value'] = b'world'
url = reverse('instance-ns-base64:subsubpattern-base64', kwargs=kwargs)
self.assertEqual(url, '/base64/aGVsbG8=/subpatterns/d29ybGQ=/d29ybGQ=/')

def test_path_inclusion_is_matchable(self):
match = resolve('/included_urls/extra/something/')
self.assertEqual(match.url_name, 'inner-extra')
Expand Down

0 comments on commit b0b4aac

Please sign in to comment.