anishgirianish commented on code in PR #62343:
URL: https://github.com/apache/airflow/pull/62343#discussion_r3157908409


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py:
##########
@@ -57,24 +60,53 @@
 from airflow.configuration import conf
 from airflow.exceptions import AirflowNotFoundException
 from airflow.models import Connection
+from airflow.models.connection_test import ACTIVE_STATES, ConnectionTestRequest
 from airflow.secrets.environment_variables import CONN_ENV_PREFIX
 from airflow.utils.db import create_default_connections as 
db_create_default_connections
 from airflow.utils.strings import get_random_string
 
 connections_router = AirflowRouter(tags=["Connection"], prefix="/connections")
 
 
+def _ensure_test_connection_enabled() -> None:
+    """Raise 403 if connection testing is not enabled in the Airflow 
configuration."""
+    if conf.get("core", "test_connection", 
fallback="Disabled").lower().strip() != "enabled":
+        raise HTTPException(
+            status.HTTP_403_FORBIDDEN,
+            "Testing connections is disabled in Airflow configuration. "
+            "Contact your deployment admin to enable it.",
+        )
+
+
+def _check_no_active_test(connection_id: str, session: SessionDep) -> None:
+    """Raise 409 if there is an active connection test request for the given 
connection_id."""
+    active_test = session.scalar(
+        select(ConnectionTestRequest).filter(
+            ConnectionTestRequest.connection_id == connection_id,
+            ConnectionTestRequest.state.in_(ACTIVE_STATES),
+        )
+    )
+    if active_test is not None:
+        raise HTTPException(
+            status.HTTP_409_CONFLICT,
+            f"Cannot modify connection `{connection_id}` while an async test 
is running. "
+            "This typically takes only a few seconds — please retry shortly.",
+        )
+

Review Comment:
   Dropped the app-layer guard. The DB now enforces it: a single column tracks 
"active test for this connection" and a unique constraint blocks duplicates. 
Thank you



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to