Opened 8 years ago

Last modified 8 years ago

#26597 closed Bug

Optparse for `noinput` and `interactive` can produce unwanted results when passed togeather — at Initial Version

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

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

You can end up with the dictionary returning .item back in one of two orders when you pass both interactive and noinput.

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

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), ('interactive', False)]}
or
{{'noinput': 'interactive'}.get(key, key): value for key, value in [('verbosity', 0), ('fake', True), ('list', True), ('fake_initial', True), ('app_label', 'tests'), ('interactive', False), ('noinput', True)]}

leading to interactive being False or True, respectively.

The weird thing, is that noinput and interactive are opposite commands and yet this code uses it for the same value. Makes my scripts sometimes fail.

Change History (0)

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