Skip to content
Latchkey

Airflow "AirflowException ... DAG ... could not be found" in CI

Airflow looked up a DAG by id (to test, trigger, or backfill it) but that id is not in the parsed DagBag. Either the file was not under the dags folder, or it failed to import so the DAG was never registered.

What this error means

A CI step running airflow dags test, airflow tasks test, or a pytest fixture fails with "airflow.exceptions.AirflowException: DAG 'my_dag' could not be found; either it does not exist or it failed to parse".

Airflow
airflow.exceptions.AirflowException: Dag 'etl_daily' could not be found;
either it does not exist or it failed to parse.

Common causes

The DAG file is outside the dags folder

AIRFLOW__CORE__DAGS_FOLDER does not point at the directory holding the DAG in CI, so it is never parsed into the DagBag.

The DAG file failed to import

An exception while importing the module means the DAG object is never created, so the id cannot be found even though the file exists.

How to fix it

Point the dags folder at your repo and list DAGs

  1. Set the dags folder to your repo path in the CI env.
  2. Run airflow dags list to confirm the id is registered.
  3. If it is missing, run airflow dags list-import-errors to see the import failure.
Terminal
export AIRFLOW__CORE__DAGS_FOLDER=$PWD/dags
airflow dags list

Fix the import error behind the missing DAG

Resolve the exception that stops the module from importing so the DAG registers.

Terminal
airflow dags list-import-errors

How to prevent it

  • Set DAGS_FOLDER explicitly in CI to your repo dags directory.
  • Gate CI on airflow dags list-import-errors returning none.
  • Keep DAG ids stable and assert them in tests.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →