On Fri, 29 Apr 2022 at 06:38, Thomas Grainger <tagrain@gmail.com> wrote:
> Can you show a run-able example of the successful and unsuccessful usage of `with DAG(): ... `?
from airflow import DAG
# correct:
dag = DAG("my_dag")
# incorrect:
DAG("my_dag")
The with construct really has nothing to do with it, but it is a
common source of confusion:
# incorrect
with DAG("my_dag"):
...
It is less obvious (to some) in this way that the entire DAG will not
be picked up. You will in fact have to write:
# correct
with DAG("my_dag") as dag:
...
This way, you're capturing the DAG in the top-level scope which is the
requirement.