﻿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
30584	call_command raises ValueError when subparser dest is passed in options.	bill parquet	Hasan Ramezani	"If a management command contains subparsers:

{{{#!python
class Command(BaseCommand):
    def add_arguments(self, parser):
        subparsers = parser.add_subparsers(title=""subcommands"",
                                           dest=""subcommand"",
                                           required=True)
        foo = subparsers.add_parser(""foo"")
        foo.set_defaults(method=self.on_foo_command)
        foo.add_argument(""--bar"")
}}}

In Django, 1.11, this could be called using

{{{#!python
call_command('mycommand', 'foo', bar=True)
}}}

With the additional argument validation in call_command, this generates `ValueError: min() arg is an empty sequence` at line 124 in `django/core/management/__init__.py` because the `_SubParsersAction.option_strings` is an empty array.

{{{#!python
    parse_args += [
        '{}={}'.format(min(opt.option_strings), arg_options[opt.dest])
        for opt in parser._actions if opt.required and opt.dest in options
    ]
}}}

If the subcommand parser is not tagged as required, `TypeError: Unknown option(s) for mycommand command: bar` occurs downstream.

The same occurs if the subcommand is passed as an option:
{{{#!python
call_command('mycommand', subcommand='foo', bar=True)
}}}
"	Bug	closed	Core (Management commands)	dev	Normal	fixed		Hasan Ramezani	Accepted	1	0	0	0	0	0
