trlopes1974 commented on issue #40119: URL: https://github.com/apache/airflow/issues/40119#issuecomment-2282733236
> @trlopes1974 is there a particular reason you want to assign the DAG only to the first task and use the dependency assignment to carry that DAG to the other tasks? In my experience it's always good to create all tasks inside a `with <my_dag>:` block so it's impossible to forget to link the tasks to the DAG, and this brings the added benefit of applying the `default_args`, including callback params, to all of the tasks. To be honest, no, there is no particular reason besides that we started using airflow recently and are certainly lack knowllege to create dags the correct way. In "my" understanding it makes no sense to have a task in the workflow that does not belong to that dag. Assigning a dag to a specific task also reduces the task reuse , you can have a task library with generic tasks that can be used in N dags, if you assign the dag in the task (like in ssh_operator = SSHOperator( task_id='ssh_operator', ..., dag=ONFAILURECALLBACK ) then, this specific task can only be used on that ONFAILURECALLBACK dag (this is my poor understanding of how things work). Anyway, regarding the use of "with dag" or "dagname=DAG...." it was a mere coincidence on the examples we have picked up to start going. -- 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]
