pythonairflowscheduledirected-acyclic-graphs

How to unpause Airflow DAG without triggering


I created a dag factory. I switch the dags to the unpause state and they immediately start working, despite the set schedule interval value. Tried to override DagModel by specifying is_active=False. Nothing helped...

I tried different methods of influence: API, Sessions, etc. I need to automatically switch dags to unpause so that they work strictly according to schedule and do not start immediately


Solution

  • Have you made sure your start_date is set correctly in your DAG? If it's in the past, Airflow will try to run all missed DAG runs from that time up until the present (if catchup=False, it will run the most recent interval only). This can cause the DAG to trigger immediately upon unpausing.

    If you want the DAG to run from a specific future time, set start_date to that point & it will prevent it from running immediately.

    from airflow import DAG
    from datetime import datetime
    
    default_args = {
        'start_date': datetime(2024, 1, 1), # Future date here
    }
    
    dag = DAG(
        'my_dag',
        default_args=default_args,
        schedule_interval='@daily',
        catchup=False  # Disable backfilling
    )