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/09/21 16:38:04 UTC

[GitHub] [airflow] SamWheating commented on a change in pull request #18370: Properly fix dagrun update state endpoint

SamWheating commented on a change in pull request #18370:
URL: https://github.com/apache/airflow/pull/18370#discussion_r713225644



##########
File path: airflow/api_connexion/endpoints/dag_run_endpoint.py
##########
@@ -302,6 +306,10 @@ def update_dag_run_state(dag_id: str, dag_run_id: str, session) -> dict:
         raise BadRequest(detail=str(err))
 
     state = post_body['state']
-    dag_run.set_state(state=DagRunState(state))
-    session.merge(dag_run)
+    dag = current_app.dag_bag.get_dag(dag_id)
+    if state == State.SUCCESS:
+        set_dag_run_state_to_success(dag, dag_run.execution_date, commit=True)
+    else:
+        set_dag_run_state_to_failed(dag, dag_run.execution_date, commit=True)

Review comment:
       ```suggestion
       elif state == State.FAILED:
       	set_dag_run_state_to_failed(dag, dag_run.execution_date, commit=True)
       else:
       	raise BadRequest(f"Bad value for `state`: {state}")
   ```
   
   If the `state` field in the post body is anything other than `"success"`, this will cause the DAGRun to be marked as failed.
   
   For example, if someone tries to update a DAGRun with `{state: succes}` it will mark the DAGRun as failed due to the spelling error.
   
   I think its a lot safer to do nothing in the event of an unexpected or input. 




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