#25034: Remove attempts to access settings at import time
--------------------------------------+--------------------
     Reporter:  evansd                |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Uncategorized         |    Version:  master
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 There are currently two places (that I can find) in Django where settings
 are read at import time:
 1.
 
[https://github.com/django/django/blob/ec4f219ecb7a5e43d0353633fac4dac42d0ee492/django/core/cache/__init__.py#L32
 django/django/core/cache/__init__.py]
 2.
 
[https://github.com/django/django/blob/ec4f219ecb7a5e43d0353633fac4dac42d0ee492/django/contrib/staticfiles/urls.py#L17
 django/django/contrib/staticfiles/urls.py]

 Case 1 is causing some people confusion when attempting to import things
 in `wsgi.py`, as the import breaks if it comes before
 `DJANGO_SETTINGS_MODULE` is defined. See for example:
 [https://github.com/evansd/whitenoise/issues/31#issuecomment-104185649]

 This check also seems a bit superfluous as failing to define a default
 cache backend will trigger an `InvalidCacheBackendError` when attempting
 to access it. It's not clear that triggering `ImproperlyConfigured` on
 import adds much here.

 Case 2 is bit strange as I can't find anywhere that actually uses this
 `urls.py` file. Is it possible that it was just left in place and is now
 redundant?

 If we could remove these two cases then we have the simple rule that
 settings are not to be accessed at import time, and we won't have any
 subtle import-order requirements.

--
Ticket URL: <https://code.djangoproject.com/ticket/25034>
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/049.903d7d4ec5b42066984942fe2d6ec073%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to