{{{
# 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`.
--
Ticket URL: <https://code.djangoproject.com/ticket/26618>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
This seems like a good idea to me, I made a preliminary pull request here
for it: https://github.com/django/django/pull/6632
I'm still not sure where to put tests for it or where to edit the docs but
I'll look around.
--
Ticket URL: <https://code.djangoproject.com/ticket/26618#comment:1>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1
* needs_docs: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26618#comment:2>
* component: Error reporting => Core (Other)
* needs_tests: 1 => 0
* owner: => nobody
* needs_docs: 1 => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
I don't think any documentation changes are required.
--
Ticket URL: <https://code.djangoproject.com/ticket/26618#comment:3>
* status: new => closed
* needs_better_patch: 1 => 0
* resolution: => fixed
Comment:
In 080dd74e016fbc99d3aaecd36ef932424042b768:
Fixed #26618 -- Improved error message when AppConfig.name is invalid.
--
Ticket URL: <https://code.djangoproject.com/ticket/26618#comment:4>