You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bo...@apache.org on 2017/02/02 13:39:21 UTC

incubator-airflow git commit: [AIRFLOW-694] Fix config behaviour for empty envvar

Repository: incubator-airflow
Updated Branches:
  refs/heads/master cf102c372 -> 3e6b923f8


[AIRFLOW-694] Fix config behaviour for empty envvar

Currently, environment variable with empty value
does not overwrite the
configuration value corresponding to it.

Closes #2044 from sekikn/AIRFLOW-694


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/3e6b923f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/3e6b923f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/3e6b923f

Branch: refs/heads/master
Commit: 3e6b923f88ea012b750e1d8c089dffa5e70a586e
Parents: cf102c3
Author: Kengo Seki <se...@nttdata.co.jp>
Authored: Thu Feb 2 14:38:29 2017 +0100
Committer: Bolke de Bruin <bo...@xs4all.nl>
Committed: Thu Feb 2 14:38:48 2017 +0100

----------------------------------------------------------------------
 airflow/configuration.py |  2 +-
 tests/core.py            | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/3e6b923f/airflow/configuration.py
----------------------------------------------------------------------
diff --git a/airflow/configuration.py b/airflow/configuration.py
index 011f764..404808b 100644
--- a/airflow/configuration.py
+++ b/airflow/configuration.py
@@ -591,7 +591,7 @@ class AirflowConfigParser(ConfigParser):
 
         # first check environment variables
         option = self._get_env_var_option(section, key)
-        if option:
+        if option is not None:
             return option
 
         # ...then the config file

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/3e6b923f/tests/core.py
----------------------------------------------------------------------
diff --git a/tests/core.py b/tests/core.py
index 0f7e41d..6d53aeb 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -776,6 +776,30 @@ class CoreTest(unittest.TestCase):
         configuration.set("core", "FERNET_KEY", FERNET_KEY)
         assert configuration.has_option("core", "FERNET_KEY")
 
+    def test_config_override_original_when_non_empty_envvar_is_provided(self):
+        key = "AIRFLOW__CORE__FERNET_KEY"
+        value = "some value"
+        assert key not in os.environ
+
+        os.environ[key] = value
+        FERNET_KEY = configuration.get('core', 'FERNET_KEY')
+        assert FERNET_KEY == value
+
+        # restore the envvar back to the original state
+        del os.environ[key]
+
+    def test_config_override_original_when_empty_envvar_is_provided(self):
+        key = "AIRFLOW__CORE__FERNET_KEY"
+        value = ""
+        assert key not in os.environ
+
+        os.environ[key] = value
+        FERNET_KEY = configuration.get('core', 'FERNET_KEY')
+        assert FERNET_KEY == value
+
+        # restore the envvar back to the original state
+        del os.environ[key]
+
     def test_class_with_logger_should_have_logger_with_correct_name(self):
 
         # each class should automatically receive a logger with a correct name