From acc824f60786069e596fd0e97fa99fcef9f00fa6 Mon Sep 17 00:00:00 2001 From: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:34:44 -0600 Subject: [PATCH] Fix templated default/example values in config ref docs (#16442) We should show the actual default/example value in the configuration reference docs, not the templated values. e.g. `{dag_id}` like you get in a generated airflow.cfg, not `{{dag_id}} like is stored in the airflow.cfg template. (cherry picked from commit cc3c13c1f52a0051aea79d90bf8258e7d156d6b7) --- airflow/configuration.py | 2 +- docs/conf.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/airflow/configuration.py b/airflow/configuration.py index 53e76a67f6c37..c3595d7c24e16 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -91,7 +91,7 @@ def _default_config_file_path(file_name: str): return os.path.join(templates_dir, file_name) -def default_config_yaml() -> dict: +def default_config_yaml() -> List[dict]: """ Read Airflow configs from YAML file diff --git a/docs/conf.py b/docs/conf.py index 39426d6fd20b7..e403ffeae4ee9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -339,8 +339,20 @@ def _get_rst_filepath_from_path(filepath: str): ) in AirflowConfigParser.deprecated_options.items(): deprecated_options[deprecated_section][deprecated_key] = section, key, since_version + configs = default_config_yaml() + + # We want the default/example we show in the docs to reflect the value _after_ + # the config has been templated, not before + # e.g. {{dag_id}} in default_config.cfg -> {dag_id} in airflow.cfg, and what we want in docs + keys_to_format = ["default", "example"] + for conf_section in configs: + for option in conf_section["options"]: + for key in keys_to_format: + if option[key] and "{{" in option[key]: + option[key] = option[key].replace("{{", "{").replace("}}", "}") + jinja_contexts = { - 'config_ctx': {"configs": default_config_yaml(), "deprecated_options": deprecated_options}, + 'config_ctx': {"configs": configs, "deprecated_options": deprecated_options}, 'quick_start_ctx': { 'doc_root_url': f'https://airflow.apache.org/docs/apache-airflow/{PACKAGE_VERSION}/' if FOR_PRODUCTION