Commit f0f52126 authored by Bas Peschier's avatar Bas Peschier Committed by Tim Graham
Browse files

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.
parent 27ad12a9
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -374,11 +374,19 @@ class RegexURLResolver(LocaleRegexProvider):
                        tried.append([pattern])
                else:
                    if sub_match:
                        # Merge captured arguments in match with submatch
                        sub_match_dict = dict(match.groupdict(), **self.default_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(
                            sub_match.func,
                            sub_match.args,
                            sub_match_args,
                            sub_match_dict,
                            sub_match.url_name,
                            self.app_name or sub_match.app_name,
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ urlpatterns = [

    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'^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')),

+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ resolve_test_data = (
    # 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'}),
    ('/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/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.
    ('/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/12/no_kwargs/42/37/', 'inc-no-kwargs', None, '', 'inc-no-kwargs', views.empty_view, ('12', '42', '37'), {}),

    # Namespaces
    ('/test1/inner/42/37/', 'urlobject-view', 'testapp', 'test-ns1', 'test-ns1:urlobject-view', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),