KeyError in settings.py leads to baffling 'Unknown command' error
|Reported by:||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||1.6|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In two places in core/management/init.py, there is code like this
try: app_name = get_commands()[name] except KeyError: raise CommandError("Unknown command: %r" % name)
Unfortunately, KeyErrors from settings.py 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 settings.py 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.