#28791: ManagementUtility.execute() does not handle ImportError for invalid
settings module
-------------------------------------+-------------------------------------
               Reporter:  Marten     |          Owner:  nobody
  Kenbeek                            |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  master
  (Management commands)              |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 In
 
[https://github.com/django/django/blob/abaf0ab4a444977dc8ac07b9b63256814c352245/django/core/management/__init__.py#L316
 ManagementUtility.execute()], the code tries to load the settings, and
 catches `ImproperlyConfigured` in case the settings aren't configured.
 However, if `DJANGO_SETTINGS_MODULE` is set to an invalid module (e.g.
 from the previous project you were working on), an uncaught `ImportError`
 is raised. This causes commands that don't need the settings, such as
 `startproject`, to fail.

 It seems to me that the `ImportError` can safely be caught so that core
 commands that don't need settings can be executed. If the settings are
 accessed later on (either because the command
 
[https://github.com/django/django/blob/abaf0ab4a444977dc8ac07b9b63256814c352245/django/core/management/__init__.py#L198
 can't be found] or the command uses the settings), the `ImportError` will
 be reraised.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28791>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.1647a727dc4d2f5d37bde17ec76019dd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to