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 2021/11/25 09:08:31 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_r756686738



##########
File path: airflow/api_connexion/endpoints/dag_endpoint.py
##########
@@ -88,25 +88,68 @@ def get_dags(limit, session, offset=0, only_active=True, tags=None, dag_id_patte
 @provide_session
 def patch_dag(session, dag_id, update_mask=None):
     """Update the specific DAG"""
+    try:
+        patch_body = dag_schema.load(request.json, session=session)
+    except ValidationError as err:
+        raise BadRequest("Invalid Dag schema", 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")
+        update_mask = update_mask[0]
+        patch_body_[update_mask] = patch_body[update_mask]
+        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")
+    setattr(dag, 'is_paused', patch_body['is_paused'])
+    session.flush()
+    return dag_schema.dump(dag)
+
+
+@security.requires_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)])

Review comment:
       ```suggestion
   @security.requires_access([(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG)])
   ```

##########
File path: airflow/api_connexion/endpoints/dag_endpoint.py
##########
@@ -77,7 +77,7 @@ def get_dags(limit, session, offset=0, only_active=True, tags=None, dag_id_patte
         cond = [DagModel.tags.any(DagTag.name == tag) for tag in tags]
         dags_query = dags_query.filter(or_(*cond))
 
-    total_entries = len(dags_query.all())
+    total_entries = dags_query.count()

Review comment:
       This may give us issues later(not sure) see https://docs.sqlalchemy.org/en/14/faq/sessions.html#faq-query-deduplicating

##########
File path: airflow/api_connexion/endpoints/dag_endpoint.py
##########
@@ -88,25 +88,68 @@ def get_dags(limit, session, offset=0, only_active=True, tags=None, dag_id_patte
 @provide_session
 def patch_dag(session, dag_id, update_mask=None):
     """Update the specific DAG"""
+    try:
+        patch_body = dag_schema.load(request.json, session=session)
+    except ValidationError as err:
+        raise BadRequest("Invalid Dag schema", detail=str(err.messages))

Review comment:
       ```suggestion
           raise BadRequest(detail=str(err.messages))
   ```
   For consistency

##########
File path: airflow/api_connexion/openapi/v1.yaml
##########
@@ -441,6 +441,41 @@ paths:
         '401':
           $ref: '#/components/responses/Unauthenticated'
 
+    patch:
+      summary: Update DAGs
+      x-openapi-router-controller: airflow.api_connexion.endpoints.dag_endpoint
+      operationId: patch_dags
+      tags: [DAG]
+      parameters:
+        - $ref: '#/components/parameters/PageLimit'
+        - $ref: '#/components/parameters/PageOffset'
+        - $ref: '#/components/parameters/FilterTags'
+        - $ref: '#/components/parameters/UpdateMask'
+        - name: only_active
+          in: query
+          schema:
+            type: boolean
+            default: true
+          required: false
+          description: |
+            Only update active DAGs.
+        - name: dag_id_pattern
+          in: query
+          schema:
+            type: string
+          required: false
+          description: |
+            If set, only update DAGs with dag_ids matching this pattern.

Review comment:
       We should have these schemas in the components/parameters section so it can be reused if need arises

##########
File path: airflow/api_connexion/openapi/v1.yaml
##########
@@ -441,6 +441,41 @@ paths:
         '401':
           $ref: '#/components/responses/Unauthenticated'
 
+    patch:
+      summary: Update DAGs
+      x-openapi-router-controller: airflow.api_connexion.endpoints.dag_endpoint
+      operationId: patch_dags
+      tags: [DAG]
+      parameters:
+        - $ref: '#/components/parameters/PageLimit'
+        - $ref: '#/components/parameters/PageOffset'
+        - $ref: '#/components/parameters/FilterTags'
+        - $ref: '#/components/parameters/UpdateMask'
+        - name: only_active
+          in: query
+          schema:
+            type: boolean
+            default: true
+          required: false
+          description: |
+            Only update active DAGs.
+        - name: dag_id_pattern
+          in: query
+          schema:
+            type: string
+          required: false
+          description: |
+            If set, only update DAGs with dag_ids matching this pattern.

Review comment:
       RequestBody is needed too




-- 
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