Skip to content

Commit

Permalink
fix(boolenvvar): fixed bug while reading env if it is improperly conf…
Browse files Browse the repository at this point in the history
…igured
  • Loading branch information
nifedara committed Aug 28, 2024
1 parent bced105 commit 260fa37
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@

def get_bool_env_var(key, default=False):
value = os.environ.get(key, default)
return bool(strtobool(str(value)))
try:
return bool(strtobool(str(value)))
except Exception:
logging.warn(f"{value} for {key} is not valid")
return False


def parse_list(value, delimiter=","):
if isinstance(value, str):
return value.split(delimiter)
return value or []


CONFIG_FILE_PATH = "config.txt"
Expand Down Expand Up @@ -341,10 +351,6 @@ def not_raises(func, *args, **kwargs):
from hdx.data.dataset import Dataset
from hdx.data.vocabulary import Vocabulary

parse_list = lambda value, delimiter=",": (
value.split(delimiter) if isinstance(value, str) else value or []
)

ALLOWED_HDX_TAGS = parse_list(
os.environ.get("ALLOWED_HDX_TAGS")
or config.get("HDX", "ALLOWED_HDX_TAGS", fallback=None)
Expand Down

0 comments on commit 260fa37

Please sign in to comment.