Opened 4 years ago

Closed 4 years ago

#22066 closed Bug (duplicate)

KeyError in leads to baffling 'Unknown command' error

Reported by: michael.karl.coleman@… Owned by: nobody
Component: Core (Management commands) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


In two places in core/management/, there is code like this

        app_name = get_commands()[name]
    except KeyError:
        raise CommandError("Unknown command: %r" % name)

Unfortunately, KeyErrors from seem to get caught here, leading to a baffling error message. The fix would be to just do something like

    commands = get_commands()
    if name not in commands:
        raise CommandError("Unknown command: %r" % name)
    app_name = name

and let any KeyError from escape as a backtrace, so that the user can see and fix it directly.

Unfortunately, I don't have time to recreate this and verify that it still exists in HEAD, but just looking at the code, I think it probably does.

This is related to #19257, but I don't believe it's the same bug.

Change History (1)

comment:1 Changed 4 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

I do think that the fix for #19257 addresses your concern. Reopen if you can reproduce with master (1.7).

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