Opened 11 years ago
Closed 11 years ago
#22066 closed Bug (duplicate)
KeyError in settings.py leads to baffling 'Unknown command' error
Reported by: | 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 |
Description
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.
I do think that the fix for #19257 addresses your concern. Reopen if you can reproduce with master (1.7).