dokterbob/django-newsletter — pull request #81 by jkuczm (2013-07-23 21:50:00+00:00)
Title: Settings class bulletproofing

Settings Bulletproofing

Previous implementation had some flaws.

1. `settings.Settings.__getattr__` was called for all attributes that were not found, even for `DEFAULT_`. Retrieving `_settings.`, if neither `django.conf.settings._` nor `_settings.DEFAULT_` existed would have led to infinite recursion of retrieving `DEFAULT_DEFAULT_DEFAULT_...`.

Solved by raising `AttributeError` for nonexistent attribute names starting with prefix denoting default setting.

2. In statement `getattr(obj, 'attr_name', some_function())` function call `some_function()` is always executed, before retrieving `obj.attr_name`. So in `settings.Settings.__getattr__` default setting was always retrieved (though not returned), even if corresponding setting existed in `django.conf.settings`. If e.g. `` is required and so `DEFAULT_` is a property that raises `ImproperlyConfigured` exception this exception would have been raised even if `django.conf.settings._` existed.

Fixed by using explicit `try ... except ...`.

3. Using, in an application, setting with name that starts with `DEFAULT_` could have led to unexpected interference with mechanism of retrieving default settings.

Fixed by prefixing default setting names with underscore, so that they are much less likely to cause naming collision.