Repository navigation
Conversation
|
I think there is an issue with the defer_task method of TaskInstance, it should call render_template_fields first before calling the expand_start_trigger_args method. Otherwise non rendered fields would be passed to the triggerer to instantiate, which is a not the same behaviour as with regular operators defering afterwards. |
|
Ok overriding the expand_start_trigger_args doesn't help because the scheduler has a serialized version of the task (e.g. operator), so it won't take into account that overriden method. So now remains the question, how do we fix this issue. This is clearly a situation which hasn't been thought about. |
|
This PR must be merged before this one can. |
|
Created new PR which attempts to fix template rendering with start from trigger, as long as template rendering in triggerer isn't fixed, this PR can't be merged. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
0ea5e5a to
6ce73ff
Compare
Both do all their requests in the triggerer, so the worker they start on only hands the first request over and that round trip is wasted. Since Airflow 3.3 the triggerer renders the templated fields of a task which starts from a trigger, which was what kept these two from using it. It is opt-in because the triggerer renders with a plain Jinja environment, without the user defined macros and filters or the native rendering of the Dag, and the task no longer waits for a pool slot. A task falls back to a worker when it cannot start from the trigger: on older Airflow versions, when an argument is an XComArg, a callable or a file-like object, which the triggerer cannot resolve or receive, and when it is mapped.
6ce73ff to
b8afc1f
Compare
MSGraphAsyncOperatorandMSGraphSensordo all their requests in the triggerer, so the worker they start on only hands the first request over. With the newstart_from_trigger=Trueargument the scheduler defers the task itself and that first worker run is skipped.This PR was blocked on template rendering: a task which starts from a trigger got its trigger built from unrendered fields. That is solved since #55068 (Airflow 3.3.0), where the triggerer renders the templated fields the trigger shares with the operator. The branch is rebuilt as one commit on current
main, as the msgraph code changed a lot since it was opened.What changed since the earlier version of this PR
The earlier review asked to always start from the trigger. This version makes it opt-in instead, like
FileSensor,TimeSensor,DateTimeSensorAsyncandDataprocSubmitJobOperator, because starting from the trigger is not transparent for existing Dags:user_defined_macrosanduser_defined_filtersof the Dag, and it always renders strings, also withrender_template_as_native_obj;When a task still starts on a worker
With the argument set, a task falls back to the worker path without failing, so it can be set through
default_args:start_from_trigger, 2.11 and 3.0 honour it but do not render templates);XComArg, a callable or a file-like object: the triggerer never resolves anXComArg, and the other two cannot be serialized;start_trigger_argsfor the scheduler to use.execute(),execute_complete()and the pagination are untouched; they remain the path for those cases and for every following page or poll. For the sensor theStartTriggerArgscarry the sensortimeout, since the scheduler only applies the timeout it is handed.Tests
execute()defers;DagRun.schedule_tisdefers the task, theTriggerrow holds the arguments and, for the sensor, the task instance gets the trigger timeout, while a task which fell back is scheduled as usual;tests_common.test_utils.operators.run_deferrable, which now builds and renders the trigger fromstart_trigger_argswhen an operator starts from the trigger.Run locally on
main: the msgraph operator, sensor, trigger and notifier tests, the Power BI and Analysis Services tests and the WinRM operator tests, which share the test helper (111 passed),prekpre-commit and manual stages including mypy for providers.test_generic_transfer.pyofcommon.sqlalso uses the helper, but could not be run locally (no MySQL client library to buildmysqlclient), so that one is left to CI.Known limitation, not addressed here
For a task with
start_from_trigger, the triggerer renders every trigger of that task, not only the one the scheduler created. The triggersexecute_completedefers for the next page or the next poll hold values which were already rendered on the worker, and pass through Jinja a second time. That only matters when a rendered value itself contains Jinja markers.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Fable 5.1) following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.