Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get skipmixin working temporarily #45824

Merged
merged 1 commit into from
Jan 21, 2025
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
8 changes: 3 additions & 5 deletions airflow/models/skipmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from sqlalchemy import tuple_, update

from airflow import settings
from airflow.exceptions import AirflowException
from airflow.models.taskinstance import TaskInstance
from airflow.utils import timezone
Expand All @@ -33,7 +34,6 @@
if TYPE_CHECKING:
from sqlalchemy.orm import Session

from airflow.models.dagrun import DagRun
from airflow.models.operator import Operator
from airflow.sdk.definitions._internal.node import DAGNode

Expand Down Expand Up @@ -136,12 +136,10 @@ def skip(
session=session,
)

@provide_session
def skip_all_except(
self,
ti: TaskInstance,
branch_task_ids: None | str | Iterable[str],
session: Session = NEW_SESSION,
):
"""
Implement the logic for a branching operator.
Expand Down Expand Up @@ -178,12 +176,11 @@ def skip_all_except(

log.info("Following branch %s", branch_task_id_set)

dag_run = ti.get_dagrun(session=session)
if TYPE_CHECKING:
assert isinstance(dag_run, DagRun)
assert ti.task

task = ti.task
session = settings.Session()
dag = TaskInstance.ensure_dag(ti, session=session)

valid_task_ids = set(dag.task_ids)
Expand Down Expand Up @@ -212,6 +209,7 @@ def skip_all_except(
for branch_task_id in list(branch_task_id_set):
branch_task_id_set.update(dag.get_task(branch_task_id).get_flat_relative_ids(upstream=False))

dag_run = ti.get_dagrun(session=session)
skip_tasks = [
(t.task_id, downstream_ti.map_index)
for t in downstream_tasks
Expand Down
1 change: 0 additions & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,6 @@ def from_runtime_ti(cls, runtime_ti: RuntimeTaskInstanceProtocol) -> TaskInstanc
task=runtime_ti.task, # type: ignore[arg-type]
map_index=runtime_ti.map_index,
)
ti.refresh_from_db()

if TYPE_CHECKING:
assert ti
Expand Down
4 changes: 3 additions & 1 deletion tests/models/test_skipmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_skip_none_tasks(self):
],
ids=["list-of-task-ids", "tuple-of-task-ids", "str-task-id", "None", "empty-list"],
)
def test_skip_all_except(self, dag_maker, branch_task_ids, expected_states):
def test_skip_all_except(self, dag_maker, branch_task_ids, expected_states, session):
with dag_maker(
"dag_test_skip_all_except",
serialized=True,
Expand All @@ -110,6 +110,8 @@ def test_skip_all_except(self, dag_maker, branch_task_ids, expected_states):

SkipMixin().skip_all_except(ti=ti1, branch_task_ids=branch_task_ids)

session.expire_all()

def get_state(ti):
ti.refresh_from_db()
return ti.state
Expand Down