I am trying to define dynamics dags in Airflow from a custom function.
If the function is defined in the dag file, then the dag is effectively created.
BUT, if I put this function in a custom library (installed in the airflow env with pip) and import it in the dag file, the dag is never created, though not throwing any errors.
My actual code roughly looks like :
library.py
def create_dag(dag_id, main, default_args, schedule_interval): dag = DAG( dag_id=dag_id, default_args=default_args, schedule_interval=None ) with dag: t1 = PythonOperator( task_id="main", python_callable=main ) return dagdag.py
from library import create_dag dag_id = "test" def main(): print("foo") globals()[dag_id] = create_dag( dag_id, main, default_args, None )
As explained, if I define this function directly in dag.py, everything works fine. Any thoughts would be welcome !
Thanks in advance