You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "pierrejeambrun (via GitHub)" <gi...@apache.org> on 2024/11/01 07:50:16 UTC

Re: [PR] AIP-84 Add ability to update dag run note in PATCH dag_run endpoint [airflow]

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


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -90,21 +93,33 @@ async def patch_dag_run_state(
         raise HTTPException(404, f"Dag with id {dag_id} was not found")
 
     if update_mask:
-        if update_mask != ["state"]:
-            raise HTTPException(400, "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:
+        attr_value = getattr(patch_body, attr_name)
         if attr_name == "state":
-            state = getattr(patch_body, attr_name)
-            if state == DAGRunPatchStates.SUCCESS:
+            if attr_value is None:
+                raise HTTPException(400, "state cannot be empty when it is included in the update mask")
+            if attr_value == DAGRunPatchStates.SUCCESS:
                 set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id, commit=True)
-            elif state == DAGRunPatchStates.QUEUED:
+            elif attr_value == 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)
-
+        elif attr_name == "note":
+            # Once Authentication is implemented in this FastAPI app,
+            # user id will be added when updating dag run note
+            # Refer to https://github.com/apache/airflow/issues/43534
+            if dag_run.dag_run_note is None:
+                dag_run.note = (attr_value, None)
+            else:
+                dag_run.dag_run_note.content = attr_value

Review Comment:
   You can take a look at the legacy endpoint to see how we set the note. I don’t have access to the code but I remember it using a tuple on the association proxy of the DagRun maybe that can help.
   
   I am out of office atm, let me know if you find a solution.



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