KimchaC commented on issue #4071: [AIRFLOW-3237] Refactor example DAGs URL: https://github.com/apache/incubator-airflow/pull/4071#issuecomment-431833674 Sorry, github is wonky for me today. First it wouldn't let me post comments and then it ended up with many duplicates and when I tried to clean them up it deleted all of them. I previously wrote: > Consider also changing the code to use the with context manager so that you don't have to repeat the dag=dag parameter on each task: > ``` > dag = DAG( > 'my_dag', > start_date=datetime(2016, 1, 1)) > with dag: > op = DummyOperator('op') > > op.dag is dag # True > ``` To which @BasPH replied... > @KimchaC I generally see the 50/50 usage of passing dag object vs using dag context manager in Airflow code. All example DAGs pass the dag object to the operators. Is there a preference for either by the Airflow community? I think the airflow team should decide on a preference for the community. One of the reasons that it is not used by everyone is probably because not everyone is aware of this feature. One of the reasons for that is that the examples are not using it :) Personally I think the with statement is awesome, makes the DAG code _much_ cleaner and reduces repetition. I'd suggest adding a comment to the examples like... ``` # The with statement allows you to omit the dag parameter when initializing tasks. with dag: ... ``` I also think the clode is clearer when the DAG is initiated separately and not inside the with statement.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
