Skip to content

Commit

Permalink
Merge pull request #37 from LamaAni/removed_warning_message
Browse files Browse the repository at this point in the history
Added warning suppression to config read
  • Loading branch information
LamaAni authored Feb 22, 2021
2 parents 6cb58cd + 34e2d52 commit 9540211
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions airflow_kubernetes_job_operator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from airflow_kubernetes_job_operator.kube_api.config import DEFAULT_KUBE_CONFIG_LOCATIONS
from airflow_kubernetes_job_operator.kube_api.queries import LogLine
from airflow_kubernetes_job_operator.utils import resolve_path
from airflow.configuration import conf
from airflow.configuration import conf, log
from airflow.exceptions import AirflowConfigException
from airflow_kubernetes_job_operator.collections import (
JobRunnerDeletePolicy,
Expand All @@ -21,6 +21,20 @@
AIRFLOW_CONFIG_SECTION_NAME = "kubernetes_job_operator"


def conf_get_no_warnings_no_errors(*args, **kwargs):
old_level = log.level
try:
# must be suppressed manually since the config
# always prints (rather then raise a warning)
log.level = logging.ERROR
val = conf.get(*args, **kwargs)
except AirflowConfigException:
val = None
finally:
log.level = old_level
return val


def get(
key: str,
default=None,
Expand All @@ -32,7 +46,7 @@ def get(
collection = collection or AIRFLOW_CONFIG_SECTION_NAME
val = None
try:
val = conf.get(AIRFLOW_CONFIG_SECTION_NAME, key)
val = conf_get_no_warnings_no_errors(AIRFLOW_CONFIG_SECTION_NAME, key)
except AirflowConfigException as ex:
logging.debug(ex)

Expand Down

0 comments on commit 9540211

Please sign in to comment.