#20636: AttributeError: 'Settings' object has no attribute
'_original_allowed_hosts'
-----------------------------------+--------------------------------------
     Reporter:  aaugustin          |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  master
     Severity:  Release blocker    |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------

Comment (by claudep):

 Here is what seems to happen

 a) `get_commands()` accesses `settings.INSTALLED_APPS`, which triggers
 `Settings.__init__` (instance A)
 b) inside `Settings.__init__`, import of settings module
 (`sesame.tests.settings`)
 c) as settings is inside tests module, this is triggering a new import
 chain (sesame.tests, django, etc.) ... until django.db accesses settings
 d) `LazySettings._wrapped` is still empty (remember we are still in
 `Settings.__init__`), hence creation of a new Settings instance (B).
 e) still inside the import process, `override_settings` is setting its
 wrapped attribute to Settings B
 f) initial `Settings.__init__` finishes, so `settings._wrapped` is
 instance A
 g) `setup_test_environment` set `_original_allowed_hosts` on Settings A
 h) after tests finishes, `override_settings` restore `settings._wrapped`
 to Settings B (value of `override_settings.wrapped`, see e)
 i) `teardown_test_environment` is complaining that Settings B has no
 `_original_allowed_hosts`.

 We could point at several problems in this process:

 * `override_settings.wrapped` could be set in `enable()` instead of in
 `__init__` (to be tested, but may be #20290)
 * Django should not access settings at module import time (I already
 addressed this for django.db in 1.6)
 * Do not put your settings modules inside another module which imports
 much of Django

 I let you choose which to address first...

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20636#comment:3>
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/067.91632cb9b4a846e31feef61e5b2d8202%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to