How to run DAG from code (pycharm) ? (without getting message: No run dates were found for the given dates and dag interval)

I’m trying to debug airflow simple code (from pycharm ).

I set executor = DebugExecutor in airflow.cfg

I wrote simple code:

from airflow                  import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.dates      import days_ago

with DAG(dag_id='example_pycharm', schedule_interval=None,start_date=days_ago(3)) as dag:

    def task1_func(ti):
        print('task1: print from task 1')

    def task2_func(ti):
        print('task2: print from task 2')


    task1 = PythonOperator(task_id='task1',  python_callable=task1_func, provide_context=True)
    task2 = PythonOperator(task_id='task2',  python_callable=task2_func, provide_context=True)

task1 >> task2


if __name__ == "__main__":
    dag.run(start_date=days_ago(3))

But I’m getting message:

INFO - No run dates were found for the given dates and dag interval.

How can I run this simple DAG from pycharm (in debug mode) ?

I’ve got the same problem!!!

Hey @aamster and @laro

DebugExecutor has been deprecated from Airflow. See the details here.

To test your DAG locally you can use dag.test() from within your DAG. See the example here.

Also, would encourage you to take a look at this guide for more examples.

Hope this helps!

Thanks
Manmeet

Hi @manmeet unfortunately .test was not what I was looking for. I want the dag run state to be persisted to the DB as if it was run from the UI, as .run says that it does. I found that this rest api endpoint did exactly what I wanted. I should mention I am using LocalExecutor, and I get the same issue with .run