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 65eb086f40c Fix airflowctl connections test failing on stored 
connections (#73098)
65eb086f40c is described below

commit 65eb086f40c1e95f848998dcbd1fa573387c06c9
Author: Y-C <[email protected]>
AuthorDate: Mon Sep 14 02:39:44 2026 +0800

    Fix airflowctl connections test failing on stored connections (#73098)
    
    The API server fills the fields a test request leaves out from the stored
    connection, and decides which fields the caller meant to override from the
    keys present in the request body. Sending every unset field as an explicit
    null therefore reads as "clear these", so a stored host or port counts as
    changed and the request is refused; where it is not refused the stored
    credentials are overwritten with nulls and a blank connection gets tested.
    
    Nothing in the CLI can express an intentional null, so omitting them loses
    no caller intent.
    
    Co-authored-by: Eason09053360 
<[email protected]>
---
 airflow-ctl/src/airflowctl/api/operations.py         |  3 ++-
 airflow-ctl/tests/airflow_ctl/api/test_operations.py | 11 ++++-------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/airflow-ctl/src/airflowctl/api/operations.py 
b/airflow-ctl/src/airflowctl/api/operations.py
index 17f72f2d5d4..5a054d79a3c 100644
--- a/airflow-ctl/src/airflowctl/api/operations.py
+++ b/airflow-ctl/src/airflowctl/api/operations.py
@@ -475,7 +475,8 @@ class ConnectionsOperations(BaseOperations):
     ) -> ConnectionTestResponse | ServerResponseError:
         """Test a connection."""
         self.response = self.client.post(
-            "connections/test", json=connection.model_dump(mode="json", 
by_alias=True)
+            "connections/test",
+            json=connection.model_dump(mode="json", by_alias=True, 
exclude_none=True),
         )
         return 
ConnectionTestResponse.model_validate_json(self.response.content)
 
diff --git a/airflow-ctl/tests/airflow_ctl/api/test_operations.py 
b/airflow-ctl/tests/airflow_ctl/api/test_operations.py
index 583c6ff2342..5b6a8641905 100644
--- a/airflow-ctl/tests/airflow_ctl/api/test_operations.py
+++ b/airflow-ctl/tests/airflow_ctl/api/test_operations.py
@@ -1018,6 +1018,10 @@ class TestConnectionsOperations:
         assert response == connection_test_response
 
     def test_test_uses_schema_alias_in_request_body(self):
+        # The exact body matters beyond the alias: the server fills unset 
fields from the stored
+        # connection, keyed off ``model_fields_set``. Sending them as null 
makes a stored host/port
+        # read as "changed" and the request is rejected with 400; a connection 
without a host gets
+        # tested with its credentials wiped.
         connection = ConnectionBody(
             connection_id=self.connection_id,
             conn_type=self.conn_type,
@@ -1034,14 +1038,7 @@ class TestConnectionsOperations:
             assert request_body == {
                 "connection_id": self.connection_id,
                 "conn_type": self.conn_type,
-                "description": None,
-                "host": None,
-                "login": None,
                 "schema": self.schema_,
-                "port": None,
-                "password": None,
-                "extra": None,
-                "team_name": None,
             }
             assert "schema_" not in request_body
             return httpx.Response(200, 
json=json.loads(connection_test_response.model_dump_json()))

Reply via email to