From 14ab4a067e7919fcf129398d6b7b0bd0c9777371 Mon Sep 17 00:00:00 2001 From: Ephraim Anierobi Date: Wed, 19 Jun 2024 10:46:29 +0100 Subject: [PATCH 1/3] Remove double warning in CLI when config value is deprecated There's a double warning when getting a value for a deprecated configuration. This happens because we first check if the config exists, which issues a warning and then getting the config also issues the same warning. Now that we don't error for non-existing configs, we should not check existence before getting a config value --- airflow/cli/commands/config_command.py | 11 ++++++----- tests/cli/commands/test_config_command.py | 17 +++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/airflow/cli/commands/config_command.py b/airflow/cli/commands/config_command.py index f15972376409..82f1943d4cf8 100644 --- a/airflow/cli/commands/config_command.py +++ b/airflow/cli/commands/config_command.py @@ -24,6 +24,7 @@ from pygments.lexers.configs import IniLexer from airflow.configuration import conf +from airflow.exceptions import AirflowConfigException from airflow.utils.cli import should_use_colors from airflow.utils.code_utils import get_terminal_formatter from airflow.utils.providers_configuration_loader import providers_configuration_loaded @@ -58,8 +59,8 @@ def get_value(args): # providers are initialized. Theoretically Providers might add new sections and options # but also override defaults for existing options, so without loading all providers we # cannot be sure what is the final value of the option. - if not conf.has_option(args.section, args.option): - raise SystemExit(f"The option [{args.section}/{args.option}] is not found in config.") - - value = conf.get(args.section, args.option) - print(value) + try: + value = conf.get(args.section, args.option) + print(value) + except AirflowConfigException: + pass diff --git a/tests/cli/commands/test_config_command.py b/tests/cli/commands/test_config_command.py index 9a22e1c09f74..030303c28ec4 100644 --- a/tests/cli/commands/test_config_command.py +++ b/tests/cli/commands/test_config_command.py @@ -20,8 +20,6 @@ from io import StringIO from unittest import mock -import pytest - from airflow.cli import cli_parser from airflow.cli.commands import config_command from tests.test_utils.config import conf_vars @@ -222,13 +220,8 @@ def test_should_not_raise_exception_when_section_for_config_with_value_defined_e config_command.get_value(self.parser.parse_args(["config", "get-value", "some_section", "value"])) - @mock.patch("airflow.cli.commands.config_command.conf") - def test_should_raise_exception_when_option_is_missing(self, mock_conf): - mock_conf.has_section.return_value = True - mock_conf.has_option.return_value = False - - with pytest.raises(SystemExit) as ctx: - config_command.get_value( - self.parser.parse_args(["config", "get-value", "missing-section", "dags_folder"]) - ) - assert "The option [missing-section/dags_folder] is not found in config." == str(ctx.value) + def test_should_raise_exception_when_option_is_missing(self, caplog): + config_command.get_value( + self.parser.parse_args(["config", "get-value", "missing-section", "dags_folder"]) + ) + assert "section/key [missing-section/dags_folder] not found in config" in caplog.text From 310e8d11ed94f5c14efdcec7de62ef5036c959d5 Mon Sep 17 00:00:00 2001 From: Ephraim Anierobi Date: Thu, 20 Jun 2024 14:28:27 +0100 Subject: [PATCH 2/3] mark test_plugins_command as db_test --- tests/cli/commands/test_plugins_command.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/cli/commands/test_plugins_command.py b/tests/cli/commands/test_plugins_command.py index 8ffe521b888e..5a1c8d64e10d 100644 --- a/tests/cli/commands/test_plugins_command.py +++ b/tests/cli/commands/test_plugins_command.py @@ -21,6 +21,8 @@ from contextlib import redirect_stdout from io import StringIO +import pytest + from airflow.cli import cli_parser from airflow.cli.commands import plugins_command from airflow.hooks.base import BaseHook @@ -29,6 +31,8 @@ from tests.plugins.test_plugin import AirflowTestPlugin as ComplexAirflowPlugin from tests.test_utils.mock_plugins import mock_plugin_manager +pytestmark = pytest.mark.db_test + class PluginHook(BaseHook): pass From bb708c67e6a916c87c963e69f376dea6851f6efe Mon Sep 17 00:00:00 2001 From: Ephraim Anierobi Date: Thu, 20 Jun 2024 14:59:33 +0100 Subject: [PATCH 3/3] mark test_cli_parser.py as db_test --- tests/cli/test_cli_parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cli/test_cli_parser.py b/tests/cli/test_cli_parser.py index 9fd5bf48b0ef..2244b6dbd586 100644 --- a/tests/cli/test_cli_parser.py +++ b/tests/cli/test_cli_parser.py @@ -45,6 +45,8 @@ from airflow.providers.celery.executors.celery_executor import CeleryExecutor from tests.test_utils.config import conf_vars +pytestmark = pytest.mark.db_test + # Can not be `--snake_case` or contain uppercase letter ILLEGAL_LONG_OPTION_PATTERN = re.compile("^--[a-z]+_[a-z]+|^--.*[A-Z].*") # Only can be `-[a-z]` or `-[A-Z]`