Does this only apply to DAGfiles? Eg https://airflow.apache.org/docs/apache-airflow/1.10.12/concepts.html#scope

You can use a `__del__` method that warns on collection - like an unawaited coroutine

Also if you're in control of importing the dagfile you can record all created dags and report any that are missing from the globals of the module


On Fri, Apr 29, 2022, 7:45 AM Malthe <mborch@gmail.com> wrote:
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.