Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18845 -- Do not swallow AttributeErrors when running commands

  • Loading branch information...
commit bb7da7844ff9f11286509c22a2549bbd4553d58d 1 parent 2c8267b
Claude Paroz claudep authored
6 django/core/management/__init__.py
View
@@ -103,10 +103,12 @@ def get_commands():
_commands = dict([(name, 'django.core') for name in find_commands(__path__[0])])
# Find the installed apps
+ from django.conf import settings
try:
- from django.conf import settings
apps = settings.INSTALLED_APPS
- except (AttributeError, ImproperlyConfigured):
+ except ImproperlyConfigured:
+ # Still useful for commands that do not require functional settings,
+ # like startproject or help
apps = []
# Find and load the management module for each installed app.
21 tests/regressiontests/admin_scripts/tests.py
View
@@ -982,13 +982,11 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:NoArgsCommand")
+
class ManageSettingsWithImportError(AdminScriptTestCase):
"""Tests for manage.py when using the default settings.py file
with an import error. Ticket #14130.
"""
- def setUp(self):
- self.write_settings_with_import_error('settings.py')
-
def tearDown(self):
self.remove_settings('settings.py')
@@ -1004,12 +1002,27 @@ def write_settings_with_import_error(self, filename, apps=None, is_dir=False, sd
settings_file.write('# The next line will cause an import error:\nimport foo42bar\n')
def test_builtin_command(self):
- "import error: manage.py builtin commands shows useful diagnostic info when settings with import errors is provided"
+ """
+ import error: manage.py builtin commands shows useful diagnostic info
+ when settings with import errors is provided
+ """
+ self.write_settings_with_import_error('settings.py')
args = ['sqlall', 'admin_scripts']
out, err = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "No module named foo42bar")
+ def test_builtin_command_with_attribute_error(self):
+ """
+ manage.py builtin commands does not swallow attribute errors from bad settings (#18845)
+ """
+ self.write_settings('settings.py', sdict={'BAD_VAR': 'INSTALLED_APPS.crash'})
+ args = ['collectstatic', 'admin_scripts']
+ out, err = self.run_manage(args)
+ self.assertNoOutput(out)
+ self.assertOutput(err, "AttributeError: 'list' object has no attribute 'crash'")
+
+
class ManageValidate(AdminScriptTestCase):
def tearDown(self):
self.remove_settings('settings.py')
Please sign in to comment.
Something went wrong with that request. Please try again.