pierrejeambrun commented on code in PR #73554:
URL: https://github.com/apache/airflow/pull/73554#discussion_r4104746512
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -379,9 +391,41 @@ def ti_update_state(
Not all state transitions are valid, and transitioning to some states
requires extra information to be
passed along. (Check out the datamodels for details, the rendered docs
might not reflect this accurately)
"""
+ # The version bundle imports the routes while registering its changes.
+ from airflow.api_fastapi.execution_api.versions.v2026_10_30 import
IdentifyRetiredTaskStateUpdates
+
bind_contextvars(ti_id=str(task_instance_id))
log.debug("Updating task instance state", new_state=ti_patch_payload.state)
+ if isinstance(ti_patch_payload, TITerminalStatePayload) and (
+ ti_patch_payload.state == TerminalStateNonSuccess.SERVER_TERMINATED
+ ):
+ ti = session.scalar(
+ select(TI)
+ .where(TI.id == task_instance_id)
+ .with_for_update(of=TI)
+ .execution_options(populate_existing=True)
+ )
+ if ti is None:
+ if
session.scalar(select(TIH.task_instance_id).where(TIH.task_instance_id ==
task_instance_id)):
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
+ raise HTTPException(status_code=404, detail={"reason":
"not_found"})
+ if (ti.hostname, ti.pid) != (ti_patch_payload.hostname,
ti_patch_payload.pid) or (
+ ti_patch_payload.hostname is None or ti_patch_payload.pid is None
+ ):
+ raise HTTPException(status_code=409, detail={"reason":
"running_elsewhere"})
+ if ti.state == TaskInstanceState.RESTARTING:
+ dag = dag_bag.get_dag_for_run(dag_run=ti.dag_run, session=session)
+ if dag is None:
+ raise HTTPException(status_code=404, detail={"reason":
"dag_not_found"})
+ ti.task = dag.get_task(ti.task_id)
Review Comment:
This might still hold
--
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]