Opened 9 years ago

Closed 9 years ago

#26597 closed Bug (needsinfo)

Optparse incorrect relationship between `noinput` and `interactive` in management command

Reported by: Joseph Kahn Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords: migrate argparse command
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Joseph Kahn)

The option mapping for argparse in call_command is incorrectly mapping args. For example, it maps noinput to interactive and does not take into account that they are opposites. Here's where the bug is:

Because of the way options are parsed on:
https://github.com/django/django/blob/1.8.13/django/core/management/__init__.py#L106-L108

I assume this is present on other management commands, but I have not tested them.

(note, I simplified opt_mapping to just the example)
The following command:
arg_options = {opt_mapping.get(key, key): value for key, value in options.items()}
can be run as:
{{'noinput': 'interactive'}.get(key, key): value for key, value in [('verbosity', 0), ('fake', True), ('list', True), ('fake_initial', True), ('app_label', 'tests'), ('noinput', True)]}

leading to interactive being True.

Change History (5)

comment:1 by Joseph Kahn, 9 years ago

Description: modified (diff)

comment:2 by Joseph Kahn, 9 years ago

Description: modified (diff)

comment:3 by Joseph Kahn, 9 years ago

Summary: Optparse for `noinput` and `interactive` can produce unwanted results when passed togeatherOptparse incorrect relationship between `noinput` and `interactive` in management command

comment:4 by Claude Paroz, 9 years ago

Could you please give us an example of a call_command you wrote and where the interactive variable was reversed?

comment:5 by Claude Paroz, 9 years ago

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top