#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.f2fd1e61f93018aa0fcebed6ddd7c0df%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to