Fixed #21634 -- Prevented hiding ImproperlyConfigured when command not found

Thanks nikolay.v.golub@gmail.com for the report.
This commit is contained in:
Claude Paroz 2014-05-10 18:40:44 +02:00 committed by Erik Romijn
parent cb15231888
commit f5d4b45df1
2 changed files with 10 additions and 8 deletions

View File

@ -262,10 +262,10 @@ class ManagementUtility(object):
# Output an extra note if settings are not properly configured # Output an extra note if settings are not properly configured
try: try:
settings.INSTALLED_APPS settings.INSTALLED_APPS
except ImproperlyConfigured as e: except ImproperlyConfigured as err:
usage.append(style.NOTICE( usage.append(style.NOTICE(
"Note that only Django core commands are listed as settings " "Note that only Django core commands are listed as settings "
"are not properly configured (error: %s)." % e)) "are not properly configured (error: %s)." % err))
return '\n'.join(usage) return '\n'.join(usage)
@ -280,6 +280,8 @@ class ManagementUtility(object):
try: try:
app_name = commands[subcommand] app_name = commands[subcommand]
except KeyError: except KeyError:
# This might trigger ImproperlyConfigured (masked in get_commands)
settings.INSTALLED_APPS
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" %
(subcommand, self.prog_name)) (subcommand, self.prog_name))
sys.exit(1) sys.exit(1)

View File

@ -275,7 +275,7 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
args = ['noargs_command'] args = ['noargs_command']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertNoOutput(out) self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'") self.assertOutput(err, "settings are not configured")
def test_custom_command_with_settings(self): def test_custom_command_with_settings(self):
"default: django-admin can execute user commands if settings are provided as argument" "default: django-admin can execute user commands if settings are provided as argument"
@ -342,7 +342,7 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
args = ['noargs_command'] args = ['noargs_command']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertNoOutput(out) self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'") self.assertOutput(err, "settings are not configured")
def test_custom_command_with_settings(self): def test_custom_command_with_settings(self):
"fulldefault: django-admin can execute user commands if settings are provided as argument" "fulldefault: django-admin can execute user commands if settings are provided as argument"
@ -409,7 +409,7 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
args = ['noargs_command'] args = ['noargs_command']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertNoOutput(out) self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'") self.assertOutput(err, "settings are not configured")
def test_custom_command_with_settings(self): def test_custom_command_with_settings(self):
"minimal: django-admin can't execute user commands, even if settings are provided as argument" "minimal: django-admin can't execute user commands, even if settings are provided as argument"
@ -476,7 +476,7 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
args = ['noargs_command'] args = ['noargs_command']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertNoOutput(out) self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'") self.assertOutput(err, "settings are not configured")
def test_custom_command_with_settings(self): def test_custom_command_with_settings(self):
"alternate: django-admin can execute user commands if settings are provided as argument" "alternate: django-admin can execute user commands if settings are provided as argument"
@ -546,7 +546,7 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
args = ['noargs_command'] args = ['noargs_command']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertNoOutput(out) self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'") self.assertOutput(err, "settings are not configured")
def test_custom_command_with_settings(self): def test_custom_command_with_settings(self):
"alternate: django-admin can execute user commands if settings are provided as argument" "alternate: django-admin can execute user commands if settings are provided as argument"
@ -620,7 +620,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
args = ['noargs_command'] args = ['noargs_command']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertNoOutput(out) self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'") self.assertOutput(err, "settings are not configured")
def test_builtin_with_settings(self): def test_builtin_with_settings(self):
"directory: django-admin builtin commands succeed if settings are provided as argument" "directory: django-admin builtin commands succeed if settings are provided as argument"