Skip to content

Commit

Permalink
Docs: explicitly describe property in patterns.rst (joke2k#189)
Browse files Browse the repository at this point in the history
Hopefully this saves time for new users of django-configuration (like myself), who "just needed" to lazily evaluate a string inside a dictionary.

This doubles as an example for `RAVEN_CONFIG` which was the whole reason I was here in the first place... The actual problem I faced was that a setting remains of type `values.Value` when nested inside a dictionary. Which results in a weird issues like this:

```
2018-02-24T20:59:26.125208+00:00 app[web.1]: Traceback (most recent call last):
2018-02-24T20:59:26.125364+00:00 app[web.1]:     self.client.http_context(self.get_http_context(environ))
2018-02-24T20:59:26.125215+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/middleware.py", line 98, in __call__
2018-02-24T20:59:26.125368+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/models.py", line 54, in <lambda>
2018-02-24T20:59:26.125482+00:00 app[web.1]:     __getattr__ = lambda x, o: getattr(get_client(), o)
2018-02-24T20:59:26.125486+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/models.py", line 134, in get_client
2018-02-24T20:59:26.125613+00:00 app[web.1]:     instance = Client(**options)
2018-02-24T20:59:26.125618+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/client.py", line 147, in __init__
2018-02-24T20:59:26.125769+00:00 app[web.1]:     Client.__init__(self, *args, **kwargs)
2018-02-24T20:59:26.125771+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/base.py", line 171, in __init__
2018-02-24T20:59:26.125927+00:00 app[web.1]:     self.set_dsn(dsn, transport)
2018-02-24T20:59:26.125929+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/base.py", line 251, in set_dsn
2018-02-24T20:59:26.126063+00:00 app[web.1]:     if dsn not in self._transport_cache:
2018-02-24T20:59:26.126076+00:00 app[web.1]: TypeError: unhashable type: 'Value'
```
  • Loading branch information
asfaltboy authored and blueyed committed Feb 27, 2018
1 parent 51e2d3e commit 3883cc4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/patterns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ command line option, e.g.::

python manage.py runserver --settings=mysite.settings --configuration=Prod

Property settings
-----------------

Use a `property` to allow for computed settings. This pattern can also be used to postpone / lazy evaluate a value. E.g. useful when nesting a Value in a dictionary and a string is required::

class Prod(Configuration):
SENTRY_DSN = values.Value(None, environ_prefix=None)

@property
def RAVEN_CONFIG(self):
return {
'dsn': self.SENTRY_DSN,
}



Global settings defaults
------------------------

Expand Down

0 comments on commit 3883cc4

Please sign in to comment.