[Django] #26618: Improve error message when AppConfig.name is invalid

19 views
Skip to first unread message

Django

unread,
May 15, 2016, 7:36:53 AM5/15/16
to django-...@googlegroups.com
#26618: Improve error message when AppConfig.name is invalid
---------------------------------+--------------------
Reporter: alasdairnicol | Owner:
Type: Uncategorized | Status: new
Component: Error reporting | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26618>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 20, 2016, 4:05:10 PM5/20/16
to django-...@googlegroups.com
#26618: Improve error message when AppConfig.name is invalid
---------------------------------+--------------------------------------

Reporter: alasdairnicol | Owner:
Type: Uncategorized | Status: new
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by inondle):

* 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>

Django

unread,
May 20, 2016, 4:06:45 PM5/20/16
to django-...@googlegroups.com
#26618: Improve error message when AppConfig.name is invalid
---------------------------------+--------------------------------------

Reporter: alasdairnicol | Owner:
Type: Uncategorized | Status: new
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by inondle):

* 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>

Django

unread,
May 26, 2016, 10:23:40 AM5/26/16
to django-...@googlegroups.com
#26618: Improve error message when AppConfig.name is invalid
--------------------------------------+------------------------------------
Reporter: alasdairnicol | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Jun 2, 2016, 1:30:56 PM6/2/16
to django-...@googlegroups.com
#26618: Improve error message when AppConfig.name is invalid
--------------------------------------+------------------------------------
Reporter: alasdairnicol | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* 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>

Reply all
Reply to author
Forward
0 new messages