Skip to content
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
5 changes: 2 additions & 3 deletions airflow-core/src/airflow/jobs/triggerer_job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,17 @@ def _handle_request(self, msg: ToTriggerSupervisor, log: FilteringBoundLogger) -
resp = dr_count
elif isinstance(msg, GetDagRunState):
dr_resp = self.client.dag_runs.get_state(msg.dag_id, msg.run_id)
resp = dr_resp
resp = DagRunStateResult.from_api_response(dr_resp)
Comment thread
kaxil marked this conversation as resolved.

elif isinstance(msg, GetTICount):
ti_count = self.client.task_instances.get_count(
resp = self.client.task_instances.get_count(
dag_id=msg.dag_id,
task_ids=msg.task_ids,
task_group_id=msg.task_group_id,
logical_dates=msg.logical_dates,
run_ids=msg.run_ids,
states=msg.states,
)
resp = ti_count.model_dump_json().encode()
Comment thread
kaxil marked this conversation as resolved.
else:
raise ValueError(f"Unknown message type {type(msg)}")

Expand Down
12 changes: 8 additions & 4 deletions airflow-core/tests/unit/jobs/test_triggerer_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@ async def run(self, **args) -> AsyncIterator[TriggerEvent]:
states=self.states,
logical_dates=self.logical_dates,
)
yield TriggerEvent({"count": dag_run_states_count})
dag_run_state = await sync_to_async(RuntimeTaskInstance.get_dagrun_state)(
Comment thread
kaxil marked this conversation as resolved.
dag_id=self.trigger_dag_id,
run_id=self.run_ids[0],
)
yield TriggerEvent({"count": dag_run_states_count, "dag_run_state": dag_run_state})


@pytest.mark.xfail(
Expand All @@ -729,10 +733,10 @@ async def run(self, **args) -> AsyncIterator[TriggerEvent]:
@pytest.mark.asyncio
@pytest.mark.flaky(reruns=2, reruns_delay=10)
@pytest.mark.execution_timeout(30)
async def test_trigger_can_fetch_trigger_dag_run_count_in_deferrable(session, dag_maker):
async def test_trigger_can_fetch_trigger_dag_run_count_and_state_in_deferrable(session, dag_maker):
"""Checks that the trigger will successfully fetch the count of trigger DAG runs."""
# Create the test DAG and task
with dag_maker(dag_id="trigger_can_fetch_trigger_dag_run_count_in_deferrable", session=session):
with dag_maker(dag_id="trigger_can_fetch_trigger_dag_run_count_and_state_in_deferrable", session=session):
EmptyOperator(task_id="dummy1")
dr = dag_maker.create_dagrun()
task_instance = dr.task_instances[0]
Expand Down Expand Up @@ -766,7 +770,7 @@ async def test_trigger_can_fetch_trigger_dag_run_count_in_deferrable(session, da
task_instance.refresh_from_db()
assert task_instance.state == TaskInstanceState.SCHEDULED
assert task_instance.next_method != "__fail__"
assert task_instance.next_kwargs == {"event": {"count": 1}}
assert task_instance.next_kwargs == {"event": {"count": 1, "dag_run_state": "running"}}


class CustomTriggerWorkflowStateTrigger(BaseTrigger):
Expand Down
4 changes: 3 additions & 1 deletion task-sdk/src/airflow/sdk/execution_time/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
AssetEventsResult,
AssetResult,
ConnectionResult,
DagRunStateResult,
DeferTask,
DeleteXCom,
ErrorResponse,
Expand Down Expand Up @@ -1021,7 +1022,8 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
msg.reset_dag_run,
)
elif isinstance(msg, GetDagRunState):
resp = self.client.dag_runs.get_state(msg.dag_id, msg.run_id)
dr_resp = self.client.dag_runs.get_state(msg.dag_id, msg.run_id)
resp = DagRunStateResult.from_api_response(dr_resp)
Comment on lines +1025 to +1026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks kaxil, am trying to remove xfail in triggers.

elif isinstance(msg, GetTaskRescheduleStartDate):
resp = self.client.task_instances.get_reschedule_start_date(msg.ti_id, msg.try_number)
elif isinstance(msg, GetTICount):
Expand Down