Skip to content

Commit

Permalink
[#2429] Deprecate warning for CKAN_DB env var
Browse files Browse the repository at this point in the history
  • Loading branch information
brew committed May 18, 2015
1 parent 436bac8 commit e9cd0c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 8 additions & 4 deletions ckan/config/environment.py
Expand Up @@ -253,6 +253,14 @@ def update_config():

# Set whitelisted env vars on config object
# This is set up before globals are initialized

ckan_db = os.environ.get('CKAN_DB', None)
if ckan_db:
msg = 'Setting CKAN_DB as an env var is deprecated and will be' \
' removed in a future release. Use CKAN_SQLALCHEMY_URL instead.'
log.warn(msg)
config['sqlalchemy.url'] = ckan_db

for option in ENV_VAR_WHITELIST:
from_env = os.environ.get(ENV_VAR_WHITELIST[option], None)
if from_env:
Expand Down Expand Up @@ -354,10 +362,6 @@ def template_loaded(template):
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)

ckan_db = os.environ.get('CKAN_DB')
if ckan_db:
config['sqlalchemy.url'] = ckan_db

# for postgresql we want to enforce utf-8
sqlalchemy_url = config.get('sqlalchemy.url', '')
if sqlalchemy_url.startswith('postgresql://'):
Expand Down
16 changes: 14 additions & 2 deletions ckan/tests/config/test_environment.py
Expand Up @@ -19,7 +19,8 @@ class TestUpdateConfig(h.FunctionalTestBase):
('CKAN_DATASTORE_WRITE_URL', 'http://mynewdbwriteurl/'),
('CKAN_DATASTORE_READ_URL', 'http://mynewdbreadurl/'),
('CKAN_SOLR_URL', 'http://mynewsolrurl/solr'),
('CKAN_SITE_ID', 'my-site')
('CKAN_SITE_ID', 'my-site'),
('CKAN_DB', 'postgresql://mydeprectatesqlurl/')
]

def _setup_env_vars(self):
Expand All @@ -30,7 +31,8 @@ def _setup_env_vars(self):

def teardown(self):
for env_var, _ in self.ENV_VAR_LIST:
del os.environ[env_var]
if os.environ.get(env_var, None):
del os.environ[env_var]
# plugin.load() will force the config to update
p.load()

Expand All @@ -51,3 +53,13 @@ def test_update_config_env_vars(self):
'http://mynewdbreadurl/')
nosetools.assert_equal(config['ckan.site_id'],
'my-site')

def test_update_config_db_url_precidence(self):
'''CKAN_SQLALCHEMY_URL in the env takes precidence over CKAN_DB'''
os.environ.setdefault('CKAN_DB', 'postgresql://mydeprectatesqlurl/')
os.environ.setdefault('CKAN_SQLALCHEMY_URL',
'postgresql://mynewsqlurl/')
p.load()

nosetools.assert_equal(config['sqlalchemy.url'],
'postgresql://mynewsqlurl/')

0 comments on commit e9cd0c4

Please sign in to comment.