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

pierrejeambrun pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new be5907a2a55 [v3-0-test] Connection Extra additional test case for 
validation (#54239) (#54244)
be5907a2a55 is described below

commit be5907a2a55733c2c823010cbd1080f653f42cef
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Aug 8 18:45:10 2025 +0200

    [v3-0-test] Connection Extra additional test case for validation (#54239) 
(#54244)
    
    (cherry picked from commit adc4b8b3a6501648b6a76bbfd162b2ba326ca729)
    
    Co-authored-by: Pierre Jeambrun <[email protected]>
---
 .../core_api/routes/public/test_connections.py     | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
index 9afac754292..e00ae2bcb8d 100644
--- 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
+++ 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
@@ -1257,3 +1257,36 @@ class 
TestPostConnectionExtraBackwardCompatibility(TestConnectionEndpoint):
         connection = 
session.query(Connection).filter_by(conn_id=TEST_CONN_ID).first()
         assert connection is not None
         assert connection.extra == "{}"  # Backward compatibility: treat "" as 
empty JSON object
+
+    @pytest.mark.parametrize(
+        "extra, expected_error_message",
+        [
+            ("[1,2,3]", "Expected JSON object in `extra` field, got non-dict 
JSON"),
+            ("some_string", "Encountered non-JSON in `extra` field"),
+        ],
+    )
+    def test_post_should_fail_with_non_json_object_as_extra(
+        self, test_client, extra, expected_error_message, session
+    ):
+        """JSON primitives are a valid JSON and should raise 422 validation 
error."""
+        body = {"connection_id": TEST_CONN_ID, "conn_type": TEST_CONN_TYPE, 
"extra": extra}
+
+        response = test_client.post("/connections", json=body)
+        assert response.status_code == 422
+        assert (
+            "Value error, The `extra` field must be a valid JSON object (e.g., 
{'key': 'value'})"
+            in response.json()["detail"][0]["msg"]
+        )
+
+        _check_last_log(
+            session,
+            dag_id=None,
+            event="post_connection",
+            logical_date=None,
+            expected_extra={
+                "connection_id": "test_connection_id",
+                "conn_type": "test_type",
+                "extra": expected_error_message,
+                "method": "POST",
+            },
+        )

Reply via email to