Opened 8 years ago

Closed 8 years ago

#27799 closed Bug (wontfix)

If 'args' is used on a custom LabelCommand or AppCommand subclass, only the last positional arg is supplied to the command

Reported by: Matthew Somerville Owned by: nobody
Component: Core (Management commands) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

argparse has undefined behaviour if add_argument is called twice with the same name – Django does this for LabelCommand and AppCommand when self.args is used, the first call to parser.add_argument('args') in BaseCommand, the second in LabelCommand/AppCommand.

What appears to happen is you get only the last positional argument supplied to your command; if the '*' and the '+' had been the other way round, you would get nothing.

Change History (2)

comment:2 by Tim Graham, 8 years ago

Component: UncategorizedCore (Management commands)
Resolution: wontfix
Status: newclosed

As discussed in #django-dev, the correct solution for your use case seems to be to use the LabelCommand.label attribute rather than args. This is fixed in 1.10 with the removal of the args attribute.

Nearly 2 years after the release of 1.8 and with 1 year of support left, I don't think it's critical to change in 1.8 at this point.

Note: See TracTickets for help on using tickets.
Back to Top