hkc-8010 commented on code in PR #76908:
URL: https://github.com/apache/airflow/pull/76908#discussion_r4725668289
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -3617,38 +3671,25 @@ def _maybe_requeue_stuck_ti(self, *, ti, session,
executor):
"The DAG or task could not be found. If a failure callback
exists, it will not be run.",
exc_info=True,
)
- else:
- if task.has_on_failure_callback:
- if inspect(ti).detached:
- ti = session.merge(ti)
- _stuck_bundle_name, _stuck_bundle_version,
_stuck_version_data = (
- _resolve_ti_callback_bundle_info(ti)
- )
- # Backfill dag_version_id for legacy tasks (Pydantic
requires uuid.UUID).
- # Note: we cannot use `continue` here because this method
is not
- # inside a loop. If backfilling fails we simply skip the
callback.
- if _ensure_ti_has_dag_version_id(ti, session, self.log):
- request = TaskCallbackRequest(
- filepath=ti.dag_model.relative_fileloc or "",
- bundle_name=_stuck_bundle_name,
- bundle_version=_stuck_bundle_version,
- version_data=_stuck_version_data,
- ti=task_instance_to_runtime(
- ti, model=TIDataModel,
map_index=coordinates.public_map_index(ti)
- ),
- msg=msg,
- context_from_server=TIRunContext(
- dag_run=ti.dag_run,
- max_tries=ti.max_tries,
- variables=[],
- connections=[],
- xcom_keys_to_clear=[],
- ),
- )
- executor.send_callback(request)
- finally:
- ti.set_state(TaskInstanceState.FAILED, session=session)
- executor.fail(executor.get_task_key(ti))
+ task = None
+ # handle_failure() reads retries and fail_fast from ti.task.
+ ti.task = task
+ needs_callback = task is not None and
(task.has_on_failure_callback or task.has_on_retry_callback)
+ # Unlike process_executor_events, a missing dag_version_id only
drops the requests here; the TI
+ # is still failed so it doesn't sit in queued.
+ _send_task_failure_requests(
+ ti,
+ task=task,
+ executor=executor,
+ msg=msg,
+ needs_callback=needs_callback,
+ coordinates=coordinates,
+ session=session,
+ log=self.log,
+ )
Review Comment:
Good catch, thanks. Cherry-picked your commit (you're still the author) in
ad77c975a6. I only reworded the comment: the old `finally` set FAILED and
called `executor.fail()`, but the exception still escaped the loop afterwards,
so that TI's transaction never committed either. With the `except` it really
does get failed now. Checked that your test goes red with the `try` removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]