Skip to content

Commit

Permalink
[AIRFLOW-694] Fix config behaviour for empty envvar
Browse files Browse the repository at this point in the history
Currently, environment variable with empty value
does not overwrite the
configuration value corresponding to it.

Closes apache#2044 from sekikn/AIRFLOW-694
  • Loading branch information
sekikn authored and bolkedebruin committed Feb 2, 2017
1 parent cf102c3 commit 3e6b923
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def get(self, section, key, **kwargs):

# 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
Expand Down
24 changes: 24 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,30 @@ def test_config_throw_error_when_original_and_fallback_is_absent(self):
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
Expand Down

0 comments on commit 3e6b923

Please sign in to comment.