﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20428	ImportError is swallowed while importing settings	giovannibajo	nobody	"In django.management.get_commands, there is the following code:

{{{
        # Find the installed apps
        try:
            from django.conf import settings
            apps = settings.INSTALLED_APPS
        except (AttributeError, EnvironmentError, ImportError):
            apps = []
}}}

The problem with this code is that any ImportError raised by settings.py (eg: a missing third-party dependency) are swallowed, and this then leads to very hard-to-diagnose bugs because the settings module is half-loaded into memory, so a part of symbols might be missing.

The bug is that Django treats ImportError as an indication that settings.py does not exist, while in reality it is only a possibility; the other is that settings.py contains code that triggers ImportError.

My personal fix is to change the code as follows:

{{{
        # Find the installed apps
        from django.conf import settings
        try:
            apps = settings.INSTALLED_APPS
        except AttributeError:
            apps = []
}}}

but I don't know whether it is the right thing. I assume the code was meant to somehow work even if the settings module is missing, while this way I'm basically forcing its existence. By changing the code, I know get this exception:

{{{
    ImportError: Could not import settings 'myapp.settings' (Is it on sys.path?): No module named django_hstore
}}}

which reports the original exception, the missing dependency, and thus lets me fix it.
"	Uncategorized	closed	Uncategorized	1.4	Normal	duplicate			Unreviewed	0	0	0	0	0	0
