dataengref errors

Home / dbt / Projects and profiles

dbt: Compilation Error: Found a cycle

Found a cycle: model.shop.int_customers --> model.shop.int_orders --> model.shop.int_customers

The ref() calls form a loop, so dbt cannot order the models into a DAG. The message lists the unique ids on the cycle.

Causes · Fixes · Source

Common causes

  1. Two models reference each other directly or through a chain of models.How to confirm: Follow the unique ids in the message; each one refs the next.
  2. A model refs itself, often when an incremental model reads its own table with ref() instead of {{ this }}.How to confirm: The cycle contains a single model id.

How to fix it

Break the loop by moving shared logic into a new upstream model that both sides ref.

In incremental models, read the existing table with {{ this }}, not ref() of the same model.

select * from {{ source('app', 'orders') }}
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}

Where the message comes from

Message template in the source: Found a cycle: %s

References

Related errors

Last checked: