dabla commented on code in PR #55068:
URL: https://github.com/apache/airflow/pull/55068#discussion_r2316586465
##########
airflow-core/src/airflow/models/dagbag.py:
##########
@@ -633,6 +675,285 @@ def dagbag_report(self):
return report
+class AsyncDagBag(DagBag):
Review Comment:
Operators can have templated fields, which can contain lambda or jinja
expressions. This means that when you have an Operator which has the
start_from_trigger option but also has templated fields, that those fields have
to be rendered before it can be run on the triggerer.
To be able to render those templated fields, as the code currently stands,
you need a task (e.g. Operator) associated to that trigger to be able to render
those fields using it's render_template_fields method. But even, if we would
hypothetically say we could render those fields without the need of the
Operator, we would still need it (e.g. task) as we need a context to run the
render_template_fields against it.
And to be able to create a template context, we need a RuntimeTaskInstance,
which in turns needs a task (e.g. Operator) to be able to be instantiated.
So in code this would translate as:
```
# We need to create RuntimeTaskInstance to be able to create a template
context
runtime_ti = RuntimeTaskInstance.model_construct(
**workload.ti.model_dump(exclude_unset=True),
task=task, # this means we also need a task (e.g. operator)
)
# Once we have the RuntimeTaskInstance, we can get the template context
context = runtime_ti.get_template_context()
# Now that have the template context, we can render the templated fields
task.render_template_fields(context=context)
```
I hope this makes it more clear for you.
--
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]