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

henry3260 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 20563781c3d Fix airflow connections test returning success exit code 
on failure (#72548)
20563781c3d is described below

commit 20563781c3d9c059985e1f9b741f9414e21bd8f8
Author: Jyun-An Chen <[email protected]>
AuthorDate: Sun Sep 6 14:01:28 2026 +0800

    Fix airflow connections test returning success exit code on failure (#72548)
    
    The failure branch in connections_test only printed the error message
    without raising SystemExit(1), unlike the other two failure paths in
    the same function. Any script that checks the exit code of this
    command would treat a failed connection test as a success.
---
 airflow-core/src/airflow/cli/commands/connection_command.py     | 1 +
 airflow-core/tests/unit/cli/commands/test_connection_command.py | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/airflow-core/src/airflow/cli/commands/connection_command.py 
b/airflow-core/src/airflow/cli/commands/connection_command.py
index 48d90f15ad8..26bf7c127c5 100644
--- a/airflow-core/src/airflow/cli/commands/connection_command.py
+++ b/airflow-core/src/airflow/cli/commands/connection_command.py
@@ -469,3 +469,4 @@ def connections_test(args) -> None:
         console.print("[bold green]\nConnection success!\n")
     else:
         console.print(f"[bold][red]\nConnection failed![/bold]\n{message}\n")
+        raise SystemExit(1)
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 8f285d2db0b..fab54ce782f 100644
--- a/airflow-core/tests/unit/cli/commands/test_connection_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_connection_command.py
@@ -1107,9 +1107,10 @@ class TestCliTestConnections:
         mock_test_conn = 
mocker.patch("airflow.providers.http.hooks.http.HttpHook.test_connection")
         conn_id = "http_default"
         mock_test_conn.return_value = False, "Failed."
-        with stdout_capture as stdout:
+        with stdout_capture as stdout, pytest.raises(SystemExit) as exc_info:
             
connection_command.connections_test(self.parser.parse_args(["connections", 
"test", conn_id]))
-            assert "Connection failed!\nFailed.\n\n" in stdout.getvalue()
+        assert exc_info.value.code == 1
+        assert "Connection failed!\nFailed.\n\n" in stdout.getvalue()
 
     def test_cli_connections_test_missing_conn(self, mocker, stdout_capture):
         mocker.patch.dict(os.environ, {"AIRFLOW__CORE__TEST_CONNECTION": 
"Enabled"})

Reply via email to