Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove double warning in CLI when config value is deprecated #40319

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions airflow/cli/commands/config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 5 additions & 12 deletions tests/cli/commands/test_config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading