Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#33892 closed Bug (duplicate)

Management commands with flags using "store_false" create inverted boolean flags in call_command

Reported by: Luke Wiwatowski Owned by: nobody
Component: Core (Management commands) Version: 4.0
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 (last modified by Luke Wiwatowski)

In any management command which parses a flag using the action store_false it has an unexpected side effect when calling the management command from the call_command function. When call_command parses the arg it won't be taken into account the action and can create weird inversions of the intent of the boolean. This is only relevant to options inputs via keyword arguments, string args work as excpected.


from the command line this will work fine:

./ flush --no-input

However if called from the call_command with one of the recommended ways we might expect no_input=True to work the same but it doesn't.

from import call_command

call_command("flush", no_input=True)

You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the ":memory:" database,
and return each table to an empty state.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: 

call_command("flush", no_input=False)  # This will continue with no input required

I'm not sure how widespread this is but flush is definitely affected

Change History (3)

comment:1 Changed 14 months ago by Mariusz Felisiak

Resolution: duplicate
Status: newclosed

You should use interactive instead of no_input, see comment.

Duplicate of #33430.

comment:2 Changed 14 months ago by Mariusz Felisiak

Summary: Management commands with flags using action="store_false" create possible inverted boolean flags in call_commandManagement commands with flags using "store_false" create inverted boolean flags in call_command

comment:3 Changed 14 months ago by Luke Wiwatowski

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top