This is an automated email from the ASF dual-hosted git repository.

utkarsharma pushed a commit to branch v2-9-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit b8d4790001342a4c97f184334fccfc2ac78b2aaa
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Thu Jun 20 15:50:01 2024 +0100

    Remove double warning in CLI  when config value is deprecated (#40319)
    
    * 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
    
    * mark test_plugins_command as db_test
    
    * mark test_cli_parser.py as db_test
    
    (cherry picked from commit 3f8c1e434346acacb80d6d0bdc255f1a657625a2)
---
 airflow/cli/commands/config_command.py     | 11 ++++++-----
 tests/cli/commands/test_config_command.py  | 17 +++++------------
 tests/cli/commands/test_plugins_command.py |  4 ++++
 tests/cli/test_cli_parser.py               |  2 ++
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/airflow/cli/commands/config_command.py 
b/airflow/cli/commands/config_command.py
index f159723764..82f1943d4c 100644
--- a/airflow/cli/commands/config_command.py
+++ b/airflow/cli/commands/config_command.py
@@ -24,6 +24,7 @@ import pygments
 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 9a22e1c09f..030303c28e 100644
--- a/tests/cli/commands/test_config_command.py
+++ b/tests/cli/commands/test_config_command.py
@@ -20,8 +20,6 @@ import contextlib
 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 @@ class TestCliConfigGetValue:
 
         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
diff --git a/tests/cli/commands/test_plugins_command.py 
b/tests/cli/commands/test_plugins_command.py
index 71d5ce5f72..846637cc83 100644
--- a/tests/cli/commands/test_plugins_command.py
+++ b/tests/cli/commands/test_plugins_command.py
@@ -21,6 +21,8 @@ import textwrap
 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 airflow.plugins_manager import AirflowPlugin
 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
diff --git a/tests/cli/test_cli_parser.py b/tests/cli/test_cli_parser.py
index d105b01614..55aae80cd0 100644
--- a/tests/cli/test_cli_parser.py
+++ b/tests/cli/test_cli_parser.py
@@ -41,6 +41,8 @@ from airflow.executors import executor_loader
 from airflow.executors.local_executor import LocalExecutor
 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]`

Reply via email to