Access context in Airflow subdag

Viewed 94

I have a dag called my_dag in a file called my_dag.py. It has a step that looks like:

wait_for_files = SubDagOperator(
    task_id='my_subdag_sensor',
    provide_context=True,
    subdag=create_sensor_subdag(
        parent_dag_name=dag.dag_id,
        child_dag_name='my_subdag_sensor',
        tasks=all_tasks,
        dependency_template="{{ task_instance.xcom_pull(dag_id='my_dag', task_ids='get_file_paths', key='%s') }}",
        default_arguments=my_args
    ),
    dag=dag
)

create_sensor_subdag is a python function that exists in another file that I import into my_dag.py. In create_sensor_subdag, I try to access context, like this:

def create_sensor_subdag(parent_dag_name,
                        child_dag_name,
                        tasks,
                        dependency_template,
                        default_arguments,
                        **context) -> DAG: 

   execution_date = context['ds']

Yet, I get this error: Broken DAG: [/usr/local/airflow/dags/my_dag.py] 'ds'

Why? Are you not able to access context from within a subdag?

Thanks in advance.

0 Answers
Related