From e834098f97cc21e86df706912d7d270891517dd8 Mon Sep 17 00:00:00 2001 From: Amogh Desai Date: Tue, 22 Jul 2025 18:17:59 +0530 Subject: [PATCH] Swap connections_get CLI command to use Connection instead of BaseHook from sdk --- airflow-core/src/airflow/cli/commands/connection_command.py | 4 +--- .../tests/unit/cli/commands/test_connection_command.py | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/airflow-core/src/airflow/cli/commands/connection_command.py b/airflow-core/src/airflow/cli/commands/connection_command.py index 79bd77e53bf50..7fe430c05bfe3 100644 --- a/airflow-core/src/airflow/cli/commands/connection_command.py +++ b/airflow-core/src/airflow/cli/commands/connection_command.py @@ -66,9 +66,7 @@ def _connection_mapper(conn: Connection) -> dict[str, Any]: def connections_get(args): """Get a connection.""" try: - from airflow.sdk import BaseHook - - conn = BaseHook.get_connection(args.conn_id) + conn = Connection.get_connection_from_secrets(args.conn_id) except AirflowNotFoundException: raise SystemExit("Connection not found.") AirflowConsole().print_as( diff --git a/airflow-core/tests/unit/cli/commands/test_connection_command.py b/airflow-core/tests/unit/cli/commands/test_connection_command.py index e8b6f5d98e31d..1ebb415aa0f82 100644 --- a/airflow-core/tests/unit/cli/commands/test_connection_command.py +++ b/airflow-core/tests/unit/cli/commands/test_connection_command.py @@ -30,7 +30,7 @@ from airflow.cli import cli_config, cli_parser from airflow.cli.commands import connection_command -from airflow.exceptions import AirflowException, AirflowNotFoundException +from airflow.exceptions import AirflowException from airflow.models import Connection from airflow.utils.db import merge_conn from airflow.utils.session import create_session @@ -61,8 +61,7 @@ def test_cli_connection_get(self): stdout = stdout.getvalue() assert "google-cloud-platform:///default" in stdout - def test_cli_connection_get_invalid(self, mock_supervisor_comms): - mock_supervisor_comms.send.side_effect = AirflowNotFoundException + def test_cli_connection_get_invalid(self): with pytest.raises(SystemExit, match=re.escape("Connection not found.")): connection_command.connections_get(self.parser.parse_args(["connections", "get", "INVALID"]))