Opened 11 years ago
Closed 11 years ago
#22985 closed Bug (fixed)
call_command() ignores dest from make_option() and uses kwarg name instead
| Reported by: | Markus Amalthea Magnuson | Owned by: | nobody | 
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev | 
| Severity: | Normal | Keywords: | |
| Cc: | 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
Let's say I've defined a custom manage command and added an option to it like this:
option_list = BaseCommand.option_list + (
    make_option('--myoption', action='store', dest='my_opt_var'),
)
I can now call this from the command-line like this:
./manage.py mycommand --my_opt_var=abc
And there will now be an entry in the options dictionary: options['my_opt_var']
However, if I call the same command from code:
call_command('mycommand', myoption='abc')
The added entry will instead use the name of the keyword argument: options['myoption']
I would expect call_command() to use what I've specified through the dest parameter of make_option()
Change History (8)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Yeah, I actually only tried this in 1.7b3, will try it in master and update this ticket with more info.
comment:3 by , 11 years ago
Seems like this is still the case in master. These are the steps I did to reproduce:
- Start a new project and a new app, and add the new app to settings.
 - In the new app, create the path 
management/commands/my_command.pywith all the intermediate__init__.pyfiles. - In 
my_command.pypaste the following code:from django.core.management.base import BaseCommand class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--myflag', action='store', dest='mydest', default=False) def handle(self, *args, **options): print(options) - From the command-line, run 
./manage.py shell, and then run these lines:>>> from django.core import management >>> management.call_command('my_command', myflag='abc') 
This will print:
{'settings': None, 'pythonpath': None, 'verbosity': 1, 'traceback': False, 'no_color': False, 'mydest': False, 'myflag': 'abc'}
I would expect it to print:
{'settings': None, 'pythonpath': None, 'verbosity': 1, 'traceback': False, 'no_color': False, 'mydest': 'abc'}
comment:4 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted | 
|---|---|
| Type: | Uncategorized → Bug | 
Looks reasonable.
comment:5 by , 11 years ago
You will have similar problem with Django 1.6.5 except that 'mydest' will be None instead of False.
comment:7 by , 11 years ago
| Triage Stage: | Accepted → Ready for checkin | 
|---|
comment:8 by , 11 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
Note that we've switched to
argparsein master (1.8). Could you check if the issue still exists?