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/04/03 14:41:55 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #15174: raise AlreadyExists exception when the execution_date is same

ephraimbuddy commented on a change in pull request #15174:
URL: https://github.com/apache/airflow/pull/15174#discussion_r606672209



##########
File path: airflow/api_connexion/endpoints/dag_run_endpoint.py
##########
@@ -240,6 +240,18 @@ def post_dag_run(dag_id, session):
         post_body = dagrun_schema.load(request.json, session=session)
     except ValidationError as err:
         raise BadRequest(detail=str(err))
+
+    dagrun_with_execution_date = (
+        session.query(DagRun).filter(DagRun.dag_id == dag_id,
+                                     DagRun.execution_date == post_body["execution_date"]).first()
+    )
+
+    if dagrun_with_execution_date:
+        raise AlreadyExists(
+            detail=f"DAGRun with DAG ID: '{dag_id}' and DAGRun ExecutionDate: '{post_body['execution_date']}' already "
+                   f"exists"
+        )
+

Review comment:
       Can you add execution_date to the filter in line 256 instead of another query?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org