From c6864a01b25591d3a709da8071413b69c9e35341 Mon Sep 17 00:00:00 2001 From: geekodour Date: Mon, 20 Nov 2017 12:32:14 +0530 Subject: [PATCH] Fixed #28791 -- Allowed commands that don't require settings to work if the DJANGO_SETTINGS_MODULE doesn't exist. --- django/core/management/__init__.py | 2 ++ tests/admin_scripts/tests.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index d6395e0a03..2500d0b70e 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -317,6 +317,8 @@ class ManagementUtility: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc + except ImportError as exc: + self.settings_exception = exc if settings.configured: # Start the auto-reloading dev server even if the code is broken. diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index e56d43c4bc..1670af86fb 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -236,6 +236,16 @@ class DjangoAdminNoSettings(AdminScriptTestCase): self.assertNoOutput(out) self.assertOutput(err, "No module named '?bad_settings'?", regex=True) + def test_commands_with_invalid_settings(self): + """" + Commands that don't require settings succeed if the settings file + doesn't exist. + """ + args = ['startproject'] + out, err = self.run_django_admin(args, settings_file='bad_settings') + self.assertNoOutput(out) + self.assertOutput(err, "You must provide a project name", regex=True) + class DjangoAdminDefaultSettings(AdminScriptTestCase): """A series of tests for django-admin.py when using a settings.py file that