airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [18/45] incubator-airflow git commit: [AIRFLOW-694] Fix config behaviour for empty envvar
Date Mon, 13 Mar 2017 04:45:16 GMT
[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/5405f5f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/5405f5f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/5405f5f8

Branch: refs/heads/v1-8-stable
Commit: 5405f5f83c6e20fff2dc209cd4be3d1d5ea85140
Parents: a7abcf3
Author: Kengo Seki <sekikn@nttdata.co.jp>
Authored: Thu Feb 2 14:38:29 2017 +0100
Committer: Bolke de Bruin <bolke@Bolkes-MacBook-Pro.local>
Committed: Sun Mar 12 07:56:15 2017 -0700

----------------------------------------------------------------------
 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/5405f5f8/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/5405f5f8/tests/core.py
----------------------------------------------------------------------
diff --git a/tests/core.py b/tests/core.py
index e35809d..3e76e81 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


Mime
View raw message