diff --git a/UPDATING.md b/UPDATING.md index 512b66bbd9..45674a6f71 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -24,6 +24,12 @@ assists users migrating to a new version. ## Airflow Master +### New `dag_discovery_safe_mode` config option + +If `dag_discovery_safe_mode` is enabled, only check files for DAGs if +they contain the strings "airflow" and "DAG". For backwards +compatibility, this option is enabled by default. + ### Removed deprecated import mechanism The deprecated import mechanism has been removed so the import of modules becomes more consistent and explicit. diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg index fff32a6694..81e0c41c45 100644 --- a/airflow/config_templates/default_airflow.cfg +++ b/airflow/config_templates/default_airflow.cfg @@ -182,6 +182,10 @@ dag_run_conf_overrides_params = False # Worker initialisation check to validate Metadata Database connection worker_precheck = False +# When discovering DAGs, ignore any files that don't contain the strings `DAG` and `airflow`. +dag_discovery_safe_mode = True + + [cli] # In what way should the cli access the API. The LocalClient will use the # database directly, while the json_client will use the api running on the diff --git a/airflow/models/__init__.py b/airflow/models/__init__.py index e9e2dfd9c2..1161066288 100755 --- a/airflow/models/__init__.py +++ b/airflow/models/__init__.py @@ -559,7 +559,10 @@ class DagBag(BaseDagBag, LoggingMixin): stats = [] FileLoadStat = namedtuple( 'FileLoadStat', "file duration dag_num task_num dags") - for filepath in list_py_file_paths(dag_folder, include_examples=include_examples): + + safe_mode = configuration.conf.getboolean('core', 'dag_discovery_safe_mode') + for filepath in list_py_file_paths(dag_folder, safe_mode=safe_mode, + include_examples=include_examples): try: ts = timezone.utcnow() found_dags = self.process_file(