uranusjr commented on a change in pull request #17839:
URL: https://github.com/apache/airflow/pull/17839#discussion_r697898126



##########
File path: airflow/api_connexion/endpoints/dag_run_endpoint.py
##########
@@ -271,3 +273,27 @@ def post_dag_run(dag_id, session):
         )
 
     raise AlreadyExists(detail=f"DAGRun with DAG ID: '{dag_id}' and DAGRun ID: 
'{run_id}' already exists")
+
+
[email protected]_access(
+    [
+        (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+        (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN)
+    ]
+)
+@provide_session
+def post_set_dag_run_state(dag_id: str, dag_run_id: str, session) -> dict:
+    """Set a state of a dag run."""
+    try:
+        post_body = dagrun_schema.load(request.json, session=session, 
unknown="include")
+    except ValidationError as err:
+        raise BadRequest(detail=str(err))
+    dag_run: Optional[DagRun] = session.query(DagRun).filter(DagRun.dag_id == 
dag_id, DagRun.run_id == dag_run_id).one_or_none()
+    if dag_run is None:
+        error_message = f'Dag Run id {dag_run_id} not found in dag {dag_id}'
+        raise DagRunNotFound(error_message)

Review comment:
       ```suggestion
       dag_run: Optional[DagRun] = session.query(DagRun).filter(DagRun.dag_id 
== dag_id, DagRun.run_id == dag_run_id).one_or_none()
       if dag_run is None:
           error_message = f'Dag Run id {dag_run_id} not found in dag {dag_id}'
           raise DagRunNotFound(error_message)
       try:
           post_body = dagrun_schema.load(request.json, session=session)
       except ValidationError as err:
           raise BadRequest(detail=str(err))
   ```
   
   Also, is the `unknown="include"` argument needed and why?




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