Ticket #18845: 18845-1.diff

File 18845-1.diff, 3.0 KB (added by Claude Paroz, 12 years ago)

Do not swallow too much exceptions

  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index 98f75e0..69a3ba8 100644
    a b def get_commands():  
    102102        _commands = dict([(name, 'django.core') for name in find_commands(__path__[0])])
    103103
    104104        # Find the installed apps
     105        from django.conf import settings
    105106        try:
    106             from django.conf import settings
    107107            apps = settings.INSTALLED_APPS
    108         except (AttributeError, EnvironmentError, ImportError):
     108        except ImportError:
     109            # Still useful for commands that do not require functional settings,
     110            # like startproject or help
    109111            apps = []
    110112
    111113        # Find and load the management module for each installed app.
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index a8fc7ed..a149940 100644
    a b class ManageMultipleSettings(AdminScriptTestCase):  
    981981
    982982class ManageSettingsWithImportError(AdminScriptTestCase):
    983983    """Tests for manage.py when using the default settings.py file
    984     with an import error. Ticket #14130.
     984    containing errors.
    985985    """
    986     def setUp(self):
    987         self.write_settings_with_import_error('settings.py')
    988 
    989986    def tearDown(self):
    990987        self.remove_settings('settings.py')
    991988
    class ManageSettingsWithImportError(AdminScriptTestCase):  
    1000997            settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
    1001998            settings_file.write('# The next line will cause an import error:\nimport foo42bar\n')
    1002999
    1003     def test_builtin_command(self):
    1004         "import error: manage.py builtin commands shows useful diagnostic info when settings with import errors is provided"
     1000    def test_builtin_command_with_import_error(self):
     1001        """
     1002        import error: manage.py builtin commands shows useful diagnostic info
     1003        when settings with import errors is provided (#14130).
     1004        """
     1005        self.write_settings_with_import_error('settings.py')
    10051006        args = ['sqlall', 'admin_scripts']
    10061007        out, err = self.run_manage(args)
    10071008        self.assertNoOutput(out)
    10081009        self.assertOutput(err, "No module named foo42bar")
    10091010
     1011    def test_builtin_command_with_attribute_error(self):
     1012        """
     1013        manage.py builtin commands does not swallow attribute errors from bad settings (#18845)
     1014        """
     1015        self.write_settings('settings.py', sdict={'BAD_VAR': 'INSTALLED_APPS.crash'})
     1016        args = ['collectstatic', 'admin_scripts']
     1017        out, err = self.run_manage(args)
     1018        self.assertNoOutput(out)
     1019        self.assertOutput(err, "AttributeError: 'list' object has no attribute 'crash'")
     1020
     1021
    10101022class ManageValidate(AdminScriptTestCase):
    10111023    def tearDown(self):
    10121024        self.remove_settings('settings.py')
Back to Top