You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@airflow.apache.org by on 2018/03/05 19:30:55 UTC

How to trigger a DAG with Subdags?

From the example 'example_trigger_target_dag.py' I learned that it is possible to reference the runtime parameters passed when I trigger a DAG. However it's not clear to me what's the correct way of doing something similar from a Subdag. 
I don't have the main dag_run available out of the box. I guess I can retrieve it from the DB and use it in the subdag, but is this the right way? 
Or is there a better way of passing runtime parameters to a Subdag?

Thank you,
Renzo

Re: How to trigger a DAG with Subdags?

Posted by Renzo Frigato <re...@gmail.com>.
I think I have found a simpler option:
https://gist.github.com/rentzso/2f66f5549a1091883b7009ce91dbee92#file-trigger_subdag_new-py

Renzo

On 2018/03/11 00:45:06, Renzo Frigato <re...@gmail.com> wrote: 
> Hello,
> 
> I have created an example to show a possible solution:
> https://gist.github.com/rentzso/2f66f5549a1091883b7009ce91dbee92
> 
> I modified some of the code in get_template_context and render_templates methods of the TaskInstance class to update the context with the parent_dag's run.
> Still not sure if this would be the recommended way of doing it.
> 
> Best,
> Renzo
> 
> On 2018/03/05 19:30:55, renzo.frigato@gmail.com <re...@gmail.com> wrote: 
> > From the example 'example_trigger_target_dag.py' I learned that it is possible to reference the runtime parameters passed when I trigger a DAG. However it's not clear to me what's the correct way of doing something similar from a Subdag. 
> > I don't have the main dag_run available out of the box. I guess I can retrieve it from the DB and use it in the subdag, but is this the right way? 
> > Or is there a better way of passing runtime parameters to a Subdag?
> > 
> > Thank you,
> > Renzo
> > 
> 

Re: How to trigger a DAG with Subdags?

Posted by Renzo Frigato <re...@gmail.com>.
Hello,

I have created an example to show a possible solution:
https://gist.github.com/rentzso/2f66f5549a1091883b7009ce91dbee92

I modified some of the code in get_template_context and render_templates methods of the TaskInstance class to update the context with the parent_dag's run.
Still not sure if this would be the recommended way of doing it.

Best,
Renzo

On 2018/03/05 19:30:55, renzo.frigato@gmail.com <re...@gmail.com> wrote: 
> From the example 'example_trigger_target_dag.py' I learned that it is possible to reference the runtime parameters passed when I trigger a DAG. However it's not clear to me what's the correct way of doing something similar from a Subdag. 
> I don't have the main dag_run available out of the box. I guess I can retrieve it from the DB and use it in the subdag, but is this the right way? 
> Or is there a better way of passing runtime parameters to a Subdag?
> 
> Thank you,
> Renzo
>