Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#25372 closed Bug (fixed)

TypeError on manage.py's autocomplete for subcommands that do not use argparse

Reported by: Daniel Hahler Owned by: nobody
Component: Core (Management commands) Version: master
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 (last modified by Daniel Hahler)

I am seeing an error with manage.py's autocomplete for subcommands that do not use argparse:

% DJANGO_AUTO_COMPLETE=1 COMP_WORDS="manage.py shell_plus " COMP_CWORD=2 python manage.py
Traceback (most recent call last):
  File "…/project/bin/manage.py", line 8, in <module>
    execute_from_command_line(sys.argv)
  File "…/django18/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "…/django18/django/core/management/__init__.py", line 327, in execute
    self.autocomplete()
  File "…/django18/django/core/management/__init__.py", line 264, in autocomplete
    options = sorted((k, v) for k, v in options if k.startswith(curr))
TypeError: unorderable types: NoneType() < bool()

The problem appears to be that for subcommands that do not use argparse,
s_opt.nargs does not get casted to a boolean:

if subcommand_cls.use_argparse:
    options.extend((sorted(s_opt.option_strings)[0], s_opt.nargs != 0) for s_opt in
                   parser._actions if s_opt.option_strings)
else:
    options.extend((s_opt.get_opt_string(), s_opt.nargs) for s_opt in
                   parser.option_list)

The functions documentation says this:

Subcommand options are saved as pairs. A pair consists of
the long option string (e.g. '--exclude') and a boolean
value indicating if the option requires arguments. When printing to
stdout, an equal sign is appended to options which require arguments.

PR: https://github.com/django/django/pull/5253

Change History (6)

comment:1 Changed 5 years ago by Daniel Hahler

Description: modified (diff)
Has patch: set

comment:2 Changed 5 years ago by Moritz Sichert

Can you provide a simple test case for this error?

comment:3 Changed 5 years ago by Moritz Sichert

Summary: "TypeError: unorderable types: NoneType() < bool()"TypeError on manage.py's autocomplete for subcommands that do not use argparse

comment:4 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedReady for checkin

As the issue is in deprecated code that will be removed in Django 1.10 and seems unlikely to regress, I guess we can just commit the fix.

comment:5 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In acb83308:

Fixed #25372 -- Fixed autocompletion for options of non-argparse commands.

comment:6 Changed 5 years ago by Tim Graham <timograham@…>

In 6c19d81:

[1.8.x] Fixed #25372 -- Fixed autocompletion for options of non-argparse commands.

Backport of acb833081dd3abca3bc62753103690f23fb3f0ec from master

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