﻿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
26618	Improve error message when AppConfig.name is invalid	Alasdair Nicol	nobody	"When loading the installed apps, Django will attempt to import the module using `AppConfig.name` ([https://github.com/django/django/blob/e475e849703d937e158e75e7a6d9cb99090857f6/django/apps/config.py#L142]):

{{{
        # Obtain app name here rather than in AppClass.__init__ to keep
        # all error checking for entries in INSTALLED_APPS in one place.
        try:
            app_name = cls.name
        except AttributeError:
            raise ImproperlyConfigured(
                ""'%s' must supply a name attribute."" % entry)

        # Ensure app_name points to a valid module.
        app_module = import_module(app_name)
}}}

If this fails, the `import_module` will raise `ImportError`, however it isn't immediately obvious that the problem is the `AppConfig.name` attribute.

{{{
  File ""/Users/anicol/dev/django/v/py3dj19/lib/python3.5/site-packages/django/core/management/__init__.py"", line 327, in execute
    django.setup()
  File ""/Users/anicol/dev/django/v/py3dj19/lib/python3.5/site-packages/django/__init__.py"", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File ""/Users/anicol/dev/django/v/py3dj19/lib/python3.5/site-packages/django/apps/registry.py"", line 85, in populate
    app_config = AppConfig.create(entry)
  File ""/Users/anicol/dev/django/v/py3dj19/lib/python3.5/site-packages/django/apps/config.py"", line 142, in create
    app_module = import_module(app_name)
  File ""/Users/anicol/dev/django/v/py3dj19/lib/python3.5/importlib/__init__.py"", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File ""<frozen importlib._bootstrap>"", line 986, in _gcd_import
  File ""<frozen importlib._bootstrap>"", line 969, in _find_and_load
  File ""<frozen importlib._bootstrap>"", line 956, in _find_and_load_unlocked
ImportError: No module named 'newapp'
}}}

On [http://stackoverflow.com/questions/37236047/django-1-9-can-not-find-newapp/37236151#37236151 this Stack Overflow question], the user assumes the problem is in `INSTALLED_APPS` instead of their AppConfig class.

We could catch the `ImportError` and raise `ImproperlyConfigured` instead, asking the user to check `AppConfig.name`."	Cleanup/optimization	closed	Core (Other)	dev	Normal	fixed			Accepted	1	0	0	0	0	0
