sanederchik opened a new issue, #50020: URL: https://github.com/apache/airflow/issues/50020
### What do you see as an issue? [In official docs](https://airflow.apache.org/docs/apache-airflow/stable/howto/dynamic-dag-generation.html) there have been stated several ways for dynamic DAGs generation. I found out another way which looks very convenient, so I'd like to get your opinion of it. ### Solving the problem ``` # reusable_dag.py import datetime from airflow.decorators import task from airflow import DAG DEFAULT_DAG_CONFIG = { 'schedule_interval': None, 'catchup': False, 'start_date': datetime.datetime.fromisoformat('2025-04-29'), 'default_args': { 'depends_on_past': False }, 'max_active_tasks': 1, 'max_active_runs': 1 } def reusable_dag_generator( dag_obj: DAG, printable_msg: str ): """Reusable dag generator used as a template for DAG generation""" with dag_obj: @task() def start_dag(): pass @task() def print_msg(): print(printable_msg) @task() def finish_dag(): pass start_dag() >> print_msg() >> finish_dag() return dag_obj # dag0.py from airflow import DAG from reusable_dag import reusable_dag_generator, DEFAULT_DAG_CONFIG dag = reusable_dag_generator( dag_obj=DAG( dag_id='test0', **DEFAULT_DAG_CONFIG ), printable_msg='Hello DAG0!' ) # dag1.py from airflow import DAG from reusable_dag import reusable_dag_generator, DEFAULT_DAG_CONFIG dag = reusable_dag_generator( dag_obj=DAG( dag_id='test1', **DEFAULT_DAG_CONFIG ), printable_msg='Hello DAG1!' ) ``` ### Anything else If provided way looks convenient, I would be glad to make a PR for docs enhancements. ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- 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]
