#30584: call_command doesn't recognize subparsers for parameter validation
-------------------------------------+-------------------------------------
Reporter: bparquet | Owner: nobody
Type: Bug | Status: new
Component: Core | Version: 2.2
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30584>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.13abfed1d3c460bdc425b8f75dbfcbba%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.