You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/03 01:12:23 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #19758: Api add support bulk pause resume

ephraimbuddy commented on a change in pull request #19758:
URL: https://github.com/apache/airflow/pull/19758#discussion_r818233478



##########
File path: airflow/api_connexion/endpoints/dag_endpoint.py
##########
@@ -100,25 +100,67 @@ def get_dags(
 @provide_session
 def patch_dag(*, dag_id: str, update_mask: UpdateMask = None, session: Session = NEW_SESSION) -> APIResponse:
     """Update the specific DAG"""
+    try:
+        patch_body = dag_schema.load(request.json, session=session)
+    except ValidationError as err:
+        raise BadRequest(detail=str(err.messages))
+    if update_mask:
+        patch_body_ = {}
+        if update_mask != ['is_paused']:
+            raise BadRequest(detail="Only `is_paused` field can be updated through the REST API")
+        patch_body_[update_mask[0]] = patch_body[update_mask[0]]
+        patch_body = patch_body_
     dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).one_or_none()
     if not dag:
         raise NotFound(f"Dag with id: '{dag_id}' not found")
+    dag.is_paused = patch_body['is_paused']
+    session.flush()
+    return dag_schema.dump(dag)
+
+
+@security.requires_access([(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG)])
+@format_parameters({'limit': check_limit})
+@provide_session
+def patch_dags(limit, session, offset=0, only_active=True, tags=None, dag_id_pattern=None, update_mask=None):
+    """Patch multiple DAGs."""
     try:
         patch_body = dag_schema.load(request.json, session=session)
     except ValidationError as err:
-        raise BadRequest("Invalid Dag schema", detail=str(err.messages))
+        raise BadRequest(detail=str(err.messages))
     if update_mask:
         patch_body_ = {}
-        if len(update_mask) > 1:
+        if update_mask != ['is_paused']:
             raise BadRequest(detail="Only `is_paused` field can be updated through the REST API")
         update_mask = update_mask[0]
-        if update_mask != 'is_paused':
-            raise BadRequest(detail="Only `is_paused` field can be updated through the REST API")
         patch_body_[update_mask] = patch_body[update_mask]
         patch_body = patch_body_
-    setattr(dag, 'is_paused', patch_body['is_paused'])
-    session.commit()
-    return dag_schema.dump(dag)
+    if only_active:
+        dags_query = session.query(DagModel).filter(~DagModel.is_subdag, DagModel.is_active)
+    else:
+        dags_query = session.query(DagModel).filter(~DagModel.is_subdag)
+
+    if dag_id_pattern == '~':
+        dag_id_pattern = '%'

Review comment:
       What happens when the dag_id_pattern is None? Will it update all DAGs or it won't? 
   I'll still do a real world testing though, just curious




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org