OscarLigthart commented on code in PR #59764:
URL: https://github.com/apache/airflow/pull/59764#discussion_r2824244671


##########
airflow-core/src/airflow/serialization/definitions/dag.py:
##########
@@ -1008,7 +1012,42 @@ def clear(
             tuples that should not be cleared
         :param exclude_run_ids: A set of ``run_id`` or (``run_id``)
         """
-        from airflow.models.taskinstance import clear_task_instances
+        from airflow.models.taskinstance import (
+            _get_new_task_ids,
+            _update_dagrun_to_latest_version,
+            clear_task_instances,
+        )
+
+        if only_new:
+            if not run_id:
+                raise ValueError("only_new requires run_id to be specified")
+            task_ids = _get_new_task_ids(self.dag_id, run_id, session)
+
+            if dry_run:
+                # For dry run, create temporary TaskInstance objects without 
database changes
+                # The dag_run is not affected in dry run mode
+                from airflow.models.dag_version import DagVersion
+                from airflow.models.dagbag import DBDagBag
+                from airflow.models.taskinstance import TaskInstance
+
+                scheduler_dagbag = DBDagBag(load_op_links=False)
+                latest_dag = 
scheduler_dagbag.get_latest_version_of_dag(self.dag_id, session=session)
+                dag_version = DagVersion.get_latest_version(self.dag_id, 
session=session)
+
+                tis = []
+                for task_id in sorted(task_ids):
+                    task = latest_dag.get_task(task_id)
+                    ti = TaskInstance(

Review Comment:
   I fear we need the full TaskInstance because of [this 
usage](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py#L299-L311).
 
   
   I don't think this will be used elsewhere. So what we can consider is to do 
some type checking in the API itself and convert it there. It would keep core 
cleaner, but moves the problem elsewhere.
   
   Let me know your thoughts!



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