#29079: Django settings should not cache user wrapped settings
-------------------------------------+-------------------------------------
     Reporter:  Riccardo Di          |                    Owner:  nobody
  Virgilio                           |
         Type:  Uncategorized        |                   Status:  new
    Component:  Core (Other)         |                  Version:  1.11
     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
-------------------------------------+-------------------------------------

Comment (by Riccardo Di Virgilio):

 right ok this is a basic example:


 {{{
 from django.conf import settings

 class CustomSettings(object):

     ENVIRONMENT = "production"

     @property
     def DEFAULT_FROM_EMAIL(self):
         if self.ENVIRONMENT == "production":
             return "[email protected]"
         return "[email protected]"

 obj = CustomSettings()

 settings.configure(obj)

 print(settings.DEFAULT_FROM_EMAIL, obj.DEFAULT_FROM_EMAIL)
 obj.ENVIRONMENT = settings.ENVIRONMENT = "development"
 print(settings.DEFAULT_FROM_EMAIL, obj.DEFAULT_FROM_EMAIL)

 }}}

 the output of this code on django 2.1 is :

 {{{
 [email protected] [email protected]
 [email protected] [email protected]
 }}}

 my claim is that this property should be computer each time is accessed.

 is true that django documentation says that you cannot expect runtime
 mutations to work and propagate properly trough django framework, but
 still internally I do rely on this behavior: I have internal settings that
 are generated for different environments and when I deploy django on
 production i'm deploying the settings by mutating the environment string
 and computing all properties.

 this cannot be done anymore with the new behavior.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29079#comment:2>
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/076.c9165611907dd203eb6da011a1f78051%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to