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


##########
airflow-core/src/airflow/serialization/definitions/dag.py:
##########
@@ -978,6 +984,38 @@ def clear(
         from airflow.models.taskinstance import clear_task_instances
 
         state: list[TaskInstanceState] = []
+
+        if only_new:
+            if not run_id:
+                raise ValueError("only_new requires run_id to be specified")
+
+            from airflow.models.dagbag import DBDagBag
+
+            dag_run = 
session.scalar(select(DagRun).filter_by(dag_id=self.dag_id, run_id=run_id))
+            if not dag_run:
+                raise ValueError(f"DagRun with run_id '{run_id}' not found")
+
+            dagbag = DBDagBag(load_op_links=False)
+            latest_dag = dagbag.get_latest_version_of_dag(self.dag_id, 
session=session)
+
+            if not latest_dag:
+                raise ValueError(f"Latest DAG version for '{self.dag_id}' not 
found")
+
+            current_dag = dagbag.get_dag_for_run(dag_run=dag_run, 
session=session)
+            new_task_ids = set(latest_dag.task_ids) - 
set(current_dag.task_ids) if current_dag else set()
+
+            # Update dag run to latest version
+            if new_task_ids:
+                dag_version = DagVersion.get_latest_version(self.dag_id, 
session=session)
+                if dag_version:
+                    dag_run.created_dag_version_id = dag_version.id
+                    dag_run.dag = latest_dag

Review Comment:
   I do agree that we _shouldn't_, but unfortunately we still do. Cleaning up 
our dagrun story (similar to how we did in AIP-63 for TIs) is still on my wish 
list.



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