Skip to content

Commit 6a20277

Browse files
ashbAlice Berard
authored and
Alice Berard
committed
[AIRFLOW-3099] Don't ever warn about missing sections of config (apache#4028)
Rather than looping through and setting each config variable individually, and having to know which sections are optional and which aren't, instead we can just call a single function on ConfigParser and it will read the config from the dict, and more importantly here, never error about missing sections - it will just create them as needed.
1 parent a23a1b4 commit 6a20277

File tree

2 files changed

+5
-38
lines changed

2 files changed

+5
-38
lines changed

airflow/bin/cli.py

+1-38
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# under the License.
2020

2121
from __future__ import print_function
22-
from backports.configparser import NoSectionError
2322
import logging
2423

2524
import os
@@ -488,24 +487,6 @@ def _run(args, dag, ti):
488487

489488
@cli_utils.action_logging
490489
def run(args, dag=None):
491-
# Optional sections won't log an error if they're missing in airflow.cfg.
492-
OPTIONAL_AIRFLOW_CFG_SECTIONS = [
493-
'atlas',
494-
'celery',
495-
'celery_broker_transport_options',
496-
'dask',
497-
'elasticsearch',
498-
'github_enterprise',
499-
'hive',
500-
'kerberos',
501-
'kubernetes',
502-
'kubernetes_node_selectors',
503-
'kubernetes_secrets',
504-
'ldap',
505-
'lineage',
506-
'mesos',
507-
]
508-
509490
if dag:
510491
args.dag_id = dag.dag_id
511492

@@ -519,25 +500,7 @@ def run(args, dag=None):
519500
if os.path.exists(args.cfg_path):
520501
os.remove(args.cfg_path)
521502

522-
# Do not log these properties since some may contain passwords.
523-
# This may also set default values for database properties like
524-
# core.sql_alchemy_pool_size
525-
# core.sql_alchemy_pool_recycle
526-
for section, config in conf_dict.items():
527-
for option, value in config.items():
528-
try:
529-
conf.set(section, option, value)
530-
except NoSectionError:
531-
no_section_msg = (
532-
'Section {section} Option {option} '
533-
'does not exist in the config!'
534-
).format(section=section, option=option)
535-
536-
if section in OPTIONAL_AIRFLOW_CFG_SECTIONS:
537-
log.debug(no_section_msg)
538-
else:
539-
log.error(no_section_msg)
540-
503+
conf.conf.read_dict(conf_dict, source=args.cfg_path)
541504
settings.configure_vars()
542505

543506
# IMPORTANT, have to use the NullPool, otherwise, each "run" command may leave

airflow/configuration.py

+4
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ def read(self, filenames):
286286
super(AirflowConfigParser, self).read(filenames)
287287
self._validate()
288288

289+
def read_dict(self, *args, **kwargs):
290+
super(AirflowConfigParser, self).read_dict(*args, **kwargs)
291+
self._validate()
292+
289293
def has_option(self, section, option):
290294
try:
291295
# Using self.get() to avoid reimplementing the priority order

0 commit comments

Comments
 (0)