Opened 5 years ago
Last modified 5 years ago
#32153 closed Bug
Support for list arguments inside exclusive required groups — at Version 2
| Reported by: | Mark Gajdosik | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev |
| Severity: | Normal | Keywords: | call_command, exclusive group, nargs, error |
| Cc: | Hasan Ramezani | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Are there any plans to add support for the following?
from django.core.management import BaseCommand
class Command(BaseCommand):
def add_arguments(self, parser):
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--foo', nargs='+', type=int)
def handle(self, *args, **options):
pass
When calling the above using call_command:
call_command('call_command_test', foo=[1, 2, 3])
# Raises: django.core.management.base.CommandError: Error: argument --foo: invalid int value: '[1, 2, 3]'
call_command('call_command_test', '--foo=1', '--foo=2', '--foo=3')
# Option 'foo' will be of value [3]
I can't think of any workarounds other than setting type=str (somehow, that works fine) and coercing manually. Thank you!
Change History (2)
comment:1 by , 5 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 5 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.