rawwar commented on code in PR #43508:
URL: https://github.com/apache/airflow/pull/43508#discussion_r1830963045


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -121,23 +124,34 @@ async def patch_dag_run_state(
         raise HTTPException(status.HTTP_404_NOT_FOUND, f"Dag with id {dag_id} 
was not found")
 
     if update_mask:
-        if update_mask != ["state"]:
-            raise HTTPException(
-                status.HTTP_400_BAD_REQUEST, "Only `state` field can be 
updated through the REST API"
-            )
+        for each in update_mask:
+            if each not in ALLOWED_FIELD_MASK:
+                raise HTTPException(400, f"Invalid field `{each}` in update 
mask")
     else:
-        update_mask = ["state"]
+        update_mask = ALLOWED_FIELD_MASK
 
-    for attr_name in update_mask:
-        if attr_name == "state":
-            state = getattr(patch_body, attr_name)
-            if state == DAGRunPatchStates.SUCCESS:
-                set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id, 
commit=True)
-            elif state == DAGRunPatchStates.QUEUED:
-                set_dag_run_state_to_queued(dag=dag, run_id=dag_run.run_id, 
commit=True)
-            else:
-                set_dag_run_state_to_failed(dag=dag, run_id=dag_run.run_id, 
commit=True)
+    if "state" in update_mask:
+        attr_value = getattr(patch_body, "state")
+        if attr_value == DAGRunPatchStates.SUCCESS:
+            set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id, 
commit=True, session=session)
+        elif attr_value == DAGRunPatchStates.QUEUED:
+            set_dag_run_state_to_queued(dag=dag, run_id=dag_run.run_id, 
commit=True, session=session)
+        elif attr_value == DAGRunPatchStates.FAILED:
+            set_dag_run_state_to_failed(dag=dag, run_id=dag_run.run_id, 
commit=True, session=session)
 
     dag_run = session.get(DagRun, dag_run.id)
 
+    for attr_name in update_mask:
+        attr_value = getattr(patch_body, attr_name)
+        if attr_value is None:
+            continue

Review Comment:
   when no update_mask is given, PatchBody model gives None for 
getattr(patch_body, 'note').  So, I updated the logic a bit.



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