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 all commits
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
4 changes: 4 additions & 0 deletions tests/cli/commands/test_plugins_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/test_cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand Down