Skip to content

Commit

Permalink
Don't bomb out on misconfigured environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebryant committed Jul 14, 2015
1 parent 448b438 commit 64a8cce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion django_autoconfig/environment_settings/autoconfig.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'''Pull settings from environment variables.'''

import ast
import logging
import os

LOGGER = logging.getLogger(__name__)


def get_settings_from_environment(environ):
'''Deduce settings from environment variables'''
Expand All @@ -11,7 +14,10 @@ def get_settings_from_environment(environ):
if not name.startswith('DJANGO_'):
continue
name = name.replace('DJANGO_', '', 1)
settings[name] = ast.literal_eval(value)
try:
settings[name] = ast.literal_eval(value)
except ValueError as err:
LOGGER.warn("Unable to parse setting %s=%s (%s)", name, value, err)
return settings

SETTINGS = get_settings_from_environment(os.environ)
5 changes: 4 additions & 1 deletion django_autoconfig/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ def test_environment_settings(self):
'''
import django_autoconfig.environment_settings.autoconfig
results = django_autoconfig.environment_settings.autoconfig.get_settings_from_environment(
{'DJANGO_BLAH': '"test-value"'},
{
'DJANGO_BLAH': '"test-value"',
'DJANGO_DONTWORK': 'flibble',
},
)
self.assertEqual(results, {'BLAH': 'test-value'})

Expand Down

0 comments on commit 64a8cce

Please sign in to comment.