jedcunningham commented on code in PR #59764:
URL: https://github.com/apache/airflow/pull/59764#discussion_r2824162146
##########
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:
Hmm, this makes me not super happy. I'd look at the use of this return and
see if there is another option we can do instead. e.g. maybe we return `int |
tis | set[str]` instead?
##########
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:
Review Comment:
Lets see how the other conversation shapes up first.
--
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]