Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airflow-core/src/airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def clear_task_instances(
dr.last_scheduling_decision = None
dr.start_date = None
dr.clear_number += 1
dr.queued_at = timezone.utcnow()
session.flush()


Expand Down
5 changes: 5 additions & 0 deletions airflow-core/tests/unit/models/test_cleartasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def test_clear_task_instances_on_finished_dr(self, state, last_scheduling, dag_m
ti1.state = TaskInstanceState.SUCCESS
session = dag_maker.session
session.flush()
original_queued_at = dr.queued_at

# we use order_by(task_id) here because for the test DAG structure of ours
# this is equivalent to topological sort. It would not work in general case
Expand All @@ -291,6 +292,10 @@ def test_clear_task_instances_on_finished_dr(self, state, last_scheduling, dag_m
assert dr.start_date is None
assert dr.last_scheduling_decision is None

# The initial finished run has queued_at=None, clearing should populate it.
assert original_queued_at is None
assert dr.queued_at is not None

@pytest.mark.parametrize("delete_tasks", [True, False])
def test_clear_task_instances_maybe_task_removed(self, delete_tasks, dag_maker, session):
"""This verifies the behavior of clear_task_instances re task removal.
Expand Down