diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 5b62b88578..774e6d3b42 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -158,12 +158,12 @@ class RegexURLResolver(object): p_pattern = p_pattern[1:] if isinstance(pattern, RegexURLResolver): parent = normalize(pattern.regex.pattern) - for name, (matches, pat) in pattern.reverse_dict.iteritems(): - new_matches = [] - for piece, p_args in parent: - new_matches.extend([(piece + suffix, p_args + args) - for (suffix, args) in matches]) - self._reverse_dict.appendlist(name, (new_matches, p_pattern + pat)) + for name in pattern.reverse_dict: + for matches, pat in pattern.reverse_dict.getlist(name): + new_matches = [] + for piece, p_args in parent: + new_matches.extend([(piece + suffix, p_args + args) for (suffix, args) in matches]) + self._reverse_dict.appendlist(name, (new_matches, p_pattern + pat)) else: bits = normalize(p_pattern) self._reverse_dict.appendlist(pattern.callback, (bits, p_pattern)) diff --git a/tests/regressiontests/urlpatterns_reverse/extra_urls.py b/tests/regressiontests/urlpatterns_reverse/extra_urls.py index ccf2365878..c171f6d6f9 100644 --- a/tests/regressiontests/urlpatterns_reverse/extra_urls.py +++ b/tests/regressiontests/urlpatterns_reverse/extra_urls.py @@ -8,4 +8,6 @@ from views import empty_view urlpatterns = patterns('', url(r'^e-places/(\d+)/$', empty_view, name='extra-places'), url(r'^e-people/(?P\w+)/$', empty_view, name="extra-people"), + url('', include('regressiontests.urlpatterns_reverse.included_urls2')), + url(r'^prefix/(?P\w+)/', include('regressiontests.urlpatterns_reverse.included_urls2')), ) diff --git a/tests/regressiontests/urlpatterns_reverse/included_urls2.py b/tests/regressiontests/urlpatterns_reverse/included_urls2.py new file mode 100644 index 0000000000..f414ca638c --- /dev/null +++ b/tests/regressiontests/urlpatterns_reverse/included_urls2.py @@ -0,0 +1,14 @@ +""" +These URL patterns are included in two different ways in the main urls.py, with +an extra argument present in one case. Thus, there are two different ways for +each name to resolve and Django must distinguish the possibilities based on the +argument list. +""" + +from django.conf.urls.defaults import * +from views import empty_view + +urlpatterns = patterns('', + url(r'^part/(?P\w+)/$', empty_view, name="part"), + url(r'^part2/(?:(?P\w+)/)?$', empty_view, name="part2"), +) diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py index 6ccf1443dc..379197085a 100644 --- a/tests/regressiontests/urlpatterns_reverse/tests.py +++ b/tests/regressiontests/urlpatterns_reverse/tests.py @@ -65,6 +65,12 @@ test_data = ( ('extra-places', '/e-places/10/', ['10'], {}), ('extra-people', '/e-people/fred/', ['fred'], {}), ('extra-people', '/e-people/fred/', [], {'name': 'fred'}), + ('part', '/part/one/', [], {'value': 'one'}), + ('part', '/prefix/xx/part/one/', [], {'value': 'one', 'prefix': 'xx'}), + ('part2', '/part2/one/', [], {'value': 'one'}), + ('part2', '/part2/', [], {}), + ('part2', '/prefix/xx/part2/one/', [], {'value': 'one', 'prefix': 'xx'}), + ('part2', '/prefix/xx/part2/', [], {'prefix': 'xx'}), # Regression for #9038 # These views are resolved by method name. Each method is deployed twice -