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



##########
File path: tests/api_connexion/endpoints/test_dag_run_endpoint.py
##########
@@ -1013,6 +1014,27 @@ def test_response_409(self):
             "type": EXCEPTIONS_LINK_MAP[409],
         }
 
+    def test_response_409_when_execution_date_is_same(self):
+        self._create_test_dag_run()
+
+        response = self.client.post(
+            "api/v1/dags/TEST_DAG_ID/dagRuns",
+            json={
+                "dag_run_id": "TEST_DAG_RUN_ID_2",
+                "execution_date": self.default_time,
+            },
+            environ_overrides={'REMOTE_USER': "test"},
+        )
+
+        assert response.status_code == 409, response.data
+        assert response.json == {
+            "detail": "DAGRun with DAG ID: 'TEST_DAG_ID' and "
+            "DAGRun ExecutionDate: '2020-06-11 18:00:00+00:00' already exists",

Review comment:
       ```suggestion
               "detail": "A DagRun with dag_id: 'TEST_DAG_ID' and "
               "execution_date: '2020-06-11 18:00:00+00:00' already exists",
   ```

##########
File path: airflow/api_connexion/endpoints/dag_run_endpoint.py
##########
@@ -240,14 +241,27 @@ 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_instance = (
-        session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == 
post_body["run_id"]).first()
+        session.query(DagRun)
+        .filter(
+            DagRun.dag_id == dag_id,
+            or_(DagRun.run_id == post_body["run_id"], DagRun.execution_date == 
post_body["execution_date"]),
+        )
+        .first()
     )
     if not dagrun_instance:
         dag_run = DagRun(dag_id=dag_id, run_type=DagRunType.MANUAL, 
**post_body)
         session.add(dag_run)
         session.commit()
         return dagrun_schema.dump(dag_run)
+
+    if dagrun_instance.execution_date == post_body["execution_date"]:
+        raise AlreadyExists(
+            detail=f"DAGRun with DAG ID: '{dag_id}' and "
+            f"DAGRun ExecutionDate: '{post_body['execution_date']}' already 
exists"

Review comment:
       ```suggestion
               detail=f"A DagRun with dag_id: '{dag_id}' and "
               f"execution_date: '{post_body['execution_date']}' already exists"
   ```




-- 
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:
[email protected]


Reply via email to