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

Determine fail_stop on client side when db isolated #39258

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions airflow/models/taskinstance.py
Expand Up @@ -878,6 +878,7 @@ def _handle_failure(
test_mode: bool | None = None,
context: Context | None = None,
force_fail: bool = False,
fail_stop: bool = False,
) -> None:
"""
Handle Failure for a task instance.
Expand All @@ -901,6 +902,7 @@ def _handle_failure(
context=context,
force_fail=force_fail,
session=session,
fail_stop=fail_stop,
)

_log_state(task_instance=task_instance, lead_msg="Immediate failure requested. " if force_fail else "")
Expand Down Expand Up @@ -2964,8 +2966,13 @@ def fetch_handle_failure_context(
context: Context | None = None,
force_fail: bool = False,
session: Session = NEW_SESSION,
fail_stop: bool = False,
):
"""Handle Failure for the TaskInstance."""
"""
Handle Failure for the TaskInstance.

:param fail_stop: if true, stop remaining tasks in dag
"""
get_listener_manager().hook.on_task_instance_failed(
previous_state=TaskInstanceState.RUNNING, task_instance=ti, error=error, session=session
)
Expand Down Expand Up @@ -3028,7 +3035,7 @@ def fetch_handle_failure_context(
email_for_state = operator.attrgetter("email_on_failure")
callbacks = task.on_failure_callback if task else None

if task and task.dag and task.dag.fail_stop:
if task and fail_stop:
_stop_remaining_tasks(task_instance=ti, session=session)
else:
if ti.state == TaskInstanceState.QUEUED:
Expand Down Expand Up @@ -3077,13 +3084,21 @@ def handle_failure(
:param context: Jinja2 context
:param force_fail: if True, task does not retry
"""
if TYPE_CHECKING:
assert self.task
assert self.task.dag
try:
fail_stop = self.task.dag.fail_stop
except Exception:
fail_stop = False
_handle_failure(
task_instance=self,
error=error,
session=session,
test_mode=test_mode,
context=context,
force_fail=force_fail,
fail_stop=fail_stop,
)

def is_eligible_to_retry(self):
Expand Down
8 changes: 8 additions & 0 deletions airflow/serialization/pydantic/taskinstance.py
Expand Up @@ -276,13 +276,21 @@ def handle_failure(
"""
from airflow.models.taskinstance import _handle_failure

if TYPE_CHECKING:
assert self.task
assert self.task.dag
try:
fail_stop = self.task.dag.fail_stop
except Exception:
fail_stop = False
_handle_failure(
task_instance=self,
error=error,
session=session,
test_mode=test_mode,
context=context,
force_fail=force_fail,
fail_stop=fail_stop,
)

def refresh_from_task(self, task: Operator, pool_override: str | None = None) -> None:
Expand Down