summaryrefslogtreecommitdiff
path: root/django/conf/__init__.py
diff options
context:
space:
mode:
authorAdam Chainz <me@adamj.eu>2016-12-23 15:58:06 +0000
committerTim Graham <timograham@gmail.com>2016-12-23 10:58:06 -0500
commitc1b221a9b913315998a1bcec2f29a9361a74d1ac (patch)
tree92783de6dbcb805a8181f5f4301f8bea5990e77f /django/conf/__init__.py
parent8669cf0e684696971f6b577f5023634cb16f307e (diff)
Fixed #27625 -- Made LazySettings cache attributes in __dict__.
Diffstat (limited to 'django/conf/__init__.py')
-rw-r--r--django/conf/__init__.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 4fec2ee646..f99236a778 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -49,9 +49,32 @@ class LazySettings(LazyObject):
}
def __getattr__(self, name):
+ """
+ Return the value of a setting and cache it in self.__dict__.
+ """
if self._wrapped is empty:
self._setup(name)
- return getattr(self._wrapped, name)
+ val = getattr(self._wrapped, name)
+ self.__dict__[name] = val
+ return val
+
+ def __setattr__(self, name, value):
+ """
+ Set the value of setting. Clear all cached values if _wrapped changes
+ (@override_settings does this) or clear single values when set.
+ """
+ if name == '_wrapped':
+ self.__dict__.clear()
+ else:
+ self.__dict__.pop(name, None)
+ super(LazySettings, self).__setattr__(name, value)
+
+ def __delattr__(self, name):
+ """
+ Delete a setting and clear it from cache if needed.
+ """
+ super(LazySettings, self).__delattr__(name)
+ self.__dict__.pop(name, None)
def configure(self, default_settings=global_settings, **options):
"""