Fixed #12943 -- Allowed unnamed arguments to be propagated in includes
Propagated unnamed arguments as positional arguments into included URLconfs if no named arguments are defined. Positional and keyword arguments are never combined.
This commit is contained in:
parent
27ad12a9b8
commit
f0f5212624
|
@ -374,11 +374,19 @@ class RegexURLResolver(LocaleRegexProvider):
|
||||||
tried.append([pattern])
|
tried.append([pattern])
|
||||||
else:
|
else:
|
||||||
if sub_match:
|
if sub_match:
|
||||||
|
# Merge captured arguments in match with submatch
|
||||||
sub_match_dict = dict(match.groupdict(), **self.default_kwargs)
|
sub_match_dict = dict(match.groupdict(), **self.default_kwargs)
|
||||||
sub_match_dict.update(sub_match.kwargs)
|
sub_match_dict.update(sub_match.kwargs)
|
||||||
|
|
||||||
|
# If there are *any* named groups, ignore all non-named groups.
|
||||||
|
# Otherwise, pass all non-named arguments as positional arguments.
|
||||||
|
sub_match_args = sub_match.args
|
||||||
|
if not sub_match_dict:
|
||||||
|
sub_match_args = match.groups() + sub_match.args
|
||||||
|
|
||||||
return ResolverMatch(
|
return ResolverMatch(
|
||||||
sub_match.func,
|
sub_match.func,
|
||||||
sub_match.args,
|
sub_match_args,
|
||||||
sub_match_dict,
|
sub_match_dict,
|
||||||
sub_match.url_name,
|
sub_match.url_name,
|
||||||
self.app_name or sub_match.app_name,
|
self.app_name or sub_match.app_name,
|
||||||
|
|
|
@ -50,6 +50,7 @@ urlpatterns = [
|
||||||
|
|
||||||
url(r'^included/', include('urlpatterns_reverse.included_namespace_urls')),
|
url(r'^included/', include('urlpatterns_reverse.included_namespace_urls')),
|
||||||
url(r'^inc(?P<outer>[0-9]+)/', include('urlpatterns_reverse.included_urls', namespace='inc-ns5')),
|
url(r'^inc(?P<outer>[0-9]+)/', include('urlpatterns_reverse.included_urls', namespace='inc-ns5')),
|
||||||
|
url(r'^included/([0-9]+)/', include('urlpatterns_reverse.included_namespace_urls')),
|
||||||
|
|
||||||
url(r'^ns-outer/(?P<outer>[0-9]+)/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')),
|
url(r'^ns-outer/(?P<outer>[0-9]+)/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')),
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ resolve_test_data = (
|
||||||
# Unnamed args are dropped if you have *any* kwargs in a pattern
|
# Unnamed args are dropped if you have *any* kwargs in a pattern
|
||||||
('/mixed_args/42/37/', 'mixed-args', None, '', 'mixed-args', views.empty_view, tuple(), {'arg2': '37'}),
|
('/mixed_args/42/37/', 'mixed-args', None, '', 'mixed-args', views.empty_view, tuple(), {'arg2': '37'}),
|
||||||
('/included/mixed_args/42/37/', 'inc-mixed-args', None, '', 'inc-mixed-args', views.empty_view, tuple(), {'arg2': '37'}),
|
('/included/mixed_args/42/37/', 'inc-mixed-args', None, '', 'inc-mixed-args', views.empty_view, tuple(), {'arg2': '37'}),
|
||||||
|
('/included/12/mixed_args/42/37/', 'inc-mixed-args', None, '', 'inc-mixed-args', views.empty_view, tuple(), {'arg2': '37'}),
|
||||||
|
|
||||||
# Unnamed views should have None as the url_name. Regression data for #21157.
|
# Unnamed views should have None as the url_name. Regression data for #21157.
|
||||||
('/unnamed/normal/42/37/', None, None, '', 'urlpatterns_reverse.views.empty_view', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
|
('/unnamed/normal/42/37/', None, None, '', 'urlpatterns_reverse.views.empty_view', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
|
||||||
|
@ -49,6 +50,7 @@ resolve_test_data = (
|
||||||
# If you have no kwargs, you get an args list.
|
# If you have no kwargs, you get an args list.
|
||||||
('/no_kwargs/42/37/', 'no-kwargs', None, '', 'no-kwargs', views.empty_view, ('42', '37'), {}),
|
('/no_kwargs/42/37/', 'no-kwargs', None, '', 'no-kwargs', views.empty_view, ('42', '37'), {}),
|
||||||
('/included/no_kwargs/42/37/', 'inc-no-kwargs', None, '', 'inc-no-kwargs', views.empty_view, ('42', '37'), {}),
|
('/included/no_kwargs/42/37/', 'inc-no-kwargs', None, '', 'inc-no-kwargs', views.empty_view, ('42', '37'), {}),
|
||||||
|
('/included/12/no_kwargs/42/37/', 'inc-no-kwargs', None, '', 'inc-no-kwargs', views.empty_view, ('12', '42', '37'), {}),
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
('/test1/inner/42/37/', 'urlobject-view', 'testapp', 'test-ns1', 'test-ns1:urlobject-view', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
|
('/test1/inner/42/37/', 'urlobject-view', 'testapp', 'test-ns1', 'test-ns1:urlobject-view', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
|
||||||
|
|
Loading…
Reference in New Issue