-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AIRFLOW-5391] Do not re-run skipped tasks when they are cleared (#7276)
If a task is skipped by BranchPythonOperator, BaseBranchOperator or ShortCircuitOperator and the user then clears the skipped task later, it'll execute. This is probably not the right behaviour. This commit changes that so it will be skipped again. This can be ignored by running the task again with "Ignore Task Deps" override. (cherry picked from commit 1cdab56)
- Loading branch information
Showing
10 changed files
with
571 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from airflow.ti_deps.deps.base_ti_dep import BaseTIDep | ||
|
||
|
||
class NotPreviouslySkippedDep(BaseTIDep): | ||
""" | ||
Determines if any of the task's direct upstream relatives have decided this task should | ||
be skipped. | ||
""" | ||
|
||
NAME = "Not Previously Skipped" | ||
IGNORABLE = True | ||
IS_TASK_DEP = True | ||
|
||
def _get_dep_statuses( | ||
self, ti, session, dep_context | ||
): # pylint: disable=signature-differs | ||
from airflow.models.skipmixin import ( | ||
SkipMixin, | ||
XCOM_SKIPMIXIN_KEY, | ||
XCOM_SKIPMIXIN_SKIPPED, | ||
XCOM_SKIPMIXIN_FOLLOWED, | ||
) | ||
from airflow.utils.state import State | ||
|
||
upstream = ti.task.get_direct_relatives(upstream=True) | ||
|
||
finished_tasks = dep_context.ensure_finished_tasks( | ||
ti.task.dag, ti.execution_date, session | ||
) | ||
|
||
finished_task_ids = {t.task_id for t in finished_tasks} | ||
|
||
for parent in upstream: | ||
if isinstance(parent, SkipMixin): | ||
if parent.task_id not in finished_task_ids: | ||
# This can happen if the parent task has not yet run. | ||
continue | ||
|
||
prev_result = ti.xcom_pull( | ||
task_ids=parent.task_id, key=XCOM_SKIPMIXIN_KEY | ||
) | ||
|
||
if prev_result is None: | ||
# This can happen if the parent task has not yet run. | ||
continue | ||
|
||
should_skip = False | ||
if ( | ||
XCOM_SKIPMIXIN_FOLLOWED in prev_result | ||
and ti.task_id not in prev_result[XCOM_SKIPMIXIN_FOLLOWED] | ||
): | ||
# Skip any tasks that are not in "followed" | ||
should_skip = True | ||
elif ( | ||
XCOM_SKIPMIXIN_SKIPPED in prev_result | ||
and ti.task_id in prev_result[XCOM_SKIPMIXIN_SKIPPED] | ||
): | ||
# Skip any tasks that are in "skipped" | ||
should_skip = True | ||
|
||
if should_skip: | ||
# If the parent SkipMixin has run, and the XCom result stored indicates this | ||
# ti should be skipped, set ti.state to SKIPPED and fail the rule so that the | ||
# ti does not execute. | ||
ti.set_state(State.SKIPPED, session) | ||
yield self._failing_status( | ||
reason="Skipping because of previous XCom result from parent task {}" | ||
.format(parent.task_id) | ||
) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.