kukigai commented on a change in pull request #11484:
URL: https://github.com/apache/airflow/pull/11484#discussion_r503581567



##########
File path: airflow/operators/dagrun_operator.py
##########
@@ -92,11 +97,39 @@ def execute(self, context: Dict):
             execution_date = timezone.utcnow()
 
         run_id = DagRun.generate_run_id(DagRunType.MANUAL, execution_date)
-        # Ignore MyPy type for self.execution_date because it doesn't pick up 
the timezone.parse() for strings
-        trigger_dag(
-            dag_id=self.trigger_dag_id,
-            run_id=run_id,
-            conf=self.conf,
-            execution_date=self.execution_date,
-            replace_microseconds=False,
-        )
+        try:
+            # Ignore MyPy type for self.execution_date because it doesn't pick 
up the timezone.parse() for strings
+            trigger_dag(
+                dag_id=self.trigger_dag_id,
+                run_id=run_id,
+                conf=self.conf,
+                execution_date=self.execution_date,
+                replace_microseconds=False,
+            )
+
+        except DagRunAlreadyExists as e:
+            if self.reset_dag_run:
+                self.log.info(f"Clearing {self.trigger_dag_id} on 
{self.execution_date}")

Review comment:
       updated.

##########
File path: airflow/operators/dagrun_operator.py
##########
@@ -92,11 +97,39 @@ def execute(self, context: Dict):
             execution_date = timezone.utcnow()
 
         run_id = DagRun.generate_run_id(DagRunType.MANUAL, execution_date)
-        # Ignore MyPy type for self.execution_date because it doesn't pick up 
the timezone.parse() for strings
-        trigger_dag(
-            dag_id=self.trigger_dag_id,
-            run_id=run_id,
-            conf=self.conf,
-            execution_date=self.execution_date,
-            replace_microseconds=False,
-        )
+        try:
+            # Ignore MyPy type for self.execution_date because it doesn't pick 
up the timezone.parse() for strings
+            trigger_dag(
+                dag_id=self.trigger_dag_id,
+                run_id=run_id,
+                conf=self.conf,
+                execution_date=self.execution_date,
+                replace_microseconds=False,
+            )
+
+        except DagRunAlreadyExists as e:
+            if self.reset_dag_run:
+                self.log.info(f"Clearing {self.trigger_dag_id} on 
{self.execution_date}")
+
+                # Get target dag object and call clear()
+
+                dag_model = DagModel.get_current(self.trigger_dag_id)
+                if dag_model is None:
+                    raise DagNotFound("Dag id {} not found in 
DagModel".format(self.trigger_dag_id))

Review comment:
       updated




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