Skip to content
Closed
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
7 changes: 3 additions & 4 deletions airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,9 @@ def _run_raw_task(
except (AirflowTaskTimeout, AirflowException, AirflowTaskTerminated) as e:
if not test_mode:
ti.refresh_from_db(lock_for_update=True, session=session)
# for case when task is marked as success/failed externally
# or dagrun timed out and task is marked as skipped
# current behavior doesn't hit the callbacks
if ti.state in State.finished:
# for case when task is marked as success/failed externally (and is cleared shortly afterwards)
# or dagrun timed out and task is marked as skipped current behavior doesn't hit the callbacks
if ti.state in State.finished or ti.state is None:
ti.clear_next_method_args()
TaskInstance.save_to_db(ti=ti, session=session)
return None
Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,15 @@ def task_function(ti):
assert ti.state == State.UP_FOR_RETRY

@pytest.mark.skip_if_database_isolation_mode # Does not work in db isolation mode as DB access in code
@pytest.mark.parametrize("state", [State.SUCCESS, State.FAILED, State.SKIPPED])
def test_task_sigterm_doesnt_change_state_of_finished_tasks(self, state, dag_maker):
@pytest.mark.parametrize("state", [State.SUCCESS, State.FAILED, State.SKIPPED, None])
def test_task_sigterm_doesnt_change_state_of_finished_and_cleared_tasks(self, state, dag_maker):
session = settings.Session()

def task_function(ti):
ti.state = state
session.merge(ti)
session.commit()
raise AirflowException()
raise AirflowTaskTerminated()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to dedicated exception introduced with #37613


with dag_maker("test_mark_failure_2"):
task = PythonOperator(
Expand Down