diff --git a/kedro-airflow/RELEASE.md b/kedro-airflow/RELEASE.md index 32f705069..e7ab78695 100755 --- a/kedro-airflow/RELEASE.md +++ b/kedro-airflow/RELEASE.md @@ -2,6 +2,7 @@ * Added support for Python 3.11 * Added the `--all` CLI argument to `kedro-airflow` to convert registered all pipelines at once. * Simplify the output of the `kedro airflow create` command. +* Fixed compatibility of `kedro-airflow` with older versions of the config loaders (`kedro<=0.18.2`). ## Community contributions Many thanks to the following Kedroids for contributing PRs to this release: diff --git a/kedro-airflow/kedro_airflow/plugin.py b/kedro-airflow/kedro_airflow/plugin.py index ba998dabc..cb20a9d38 100644 --- a/kedro-airflow/kedro_airflow/plugin.py +++ b/kedro-airflow/kedro_airflow/plugin.py @@ -36,17 +36,22 @@ def airflow_commands(): def _load_config(context: KedroContext) -> dict[str, Any]: + # Backwards compatibility for ConfigLoader that does not support `config_patterns` + config_loader = context.config_loader + if not hasattr(config_loader, "config_patterns"): + return config_loader.get("airflow*", "airflow/**") + # Set the default pattern for `airflow` if not provided in `settings.py` - if "airflow" not in context.config_loader.config_patterns.keys(): - context.config_loader.config_patterns.update( # pragma: no cover + if "airflow" not in config_loader.config_patterns.keys(): + config_loader.config_patterns.update( # pragma: no cover {"airflow": ["airflow*", "airflow/**"]} ) - assert "airflow" in context.config_loader.config_patterns.keys() + assert "airflow" in config_loader.config_patterns.keys() # Load the config try: - return context.config_loader["airflow"] + return config_loader["airflow"] except MissingConfigException: # File does not exist return {} diff --git a/kedro-airflow/tests/test_plugin.py b/kedro-airflow/tests/test_plugin.py index 1d282f0c3..4c11efd22 100644 --- a/kedro-airflow/tests/test_plugin.py +++ b/kedro-airflow/tests/test_plugin.py @@ -5,8 +5,11 @@ import pytest import yaml +from kedro.config import ConfigLoader +from kedro.framework.context import KedroContext +from pluggy import PluginManager -from kedro_airflow.plugin import commands +from kedro_airflow.plugin import _load_config, commands @pytest.mark.parametrize( @@ -264,3 +267,22 @@ def test_create_airflow_all_and_pipeline(cli_runner, metadata): "Error: Invalid value: The `--all` and `--pipeline` option are mutually exclusive." in result.stdout ) + + +def test_config_loader_backwards_compatibility(cli_runner, metadata): + # Emulate ConfigLoader in kedro <= 0.18.2 + conf_source = Path.cwd() / "conf" + config_loader = ConfigLoader(conf_source=conf_source) + del config_loader.config_patterns + context = KedroContext( + config_loader=config_loader, + hook_manager=PluginManager(project_name=metadata.project_name), + package_name=metadata.package_name, + project_path=metadata.project_path, + ) + + config = _load_config(context) + assert config == { + "default": {"owner": "again someone else"}, + "ds": {"owner": "finally someone else"}, + }