Airflow "Cycle detected in DAG" circular dependency in CI
A DAG must be acyclic. When task dependencies form a loop (A waits on B and B waits on A), Airflow raises AirflowDagCycleException during parsing and refuses to register the DAG.
What this error means
DAG parsing fails with "airflow.exceptions.AirflowDagCycleException: Cycle detected in DAG. Faulty task: X" naming a task involved in the loop.
airflow.exceptions.AirflowDagCycleException:
Cycle detected in DAG: failed to set relationship between
task 'transform' and task 'extract' (faulty task 'extract')Common causes
Dependencies form a loop
Two tasks set each other as upstream (directly or through a chain), producing a cycle that is not a valid DAG.
A copy-paste error in set_upstream/set_downstream
A misplaced >> or << wires a task back to one of its own ancestors.
How to fix it
Break the loop in the dependency wiring
- Find the faulty task named in the exception.
- Trace its upstream chain to the task that points back to it.
- Remove or redirect the edge so the graph is acyclic.
# acyclic: each edge points forward only
extract >> transform >> loadAssert acyclicity in a DAG test
Loading the DagBag in a test surfaces the cycle before merge.
from airflow.models import DagBag
assert not DagBag().import_errorsHow to prevent it
- Wire dependencies in one direction with
>>chains. - Add a DagBag import test to CI to catch cycles.
- Review dependency edits carefully in shared DAGs.