First time dbt-core user: RuntimeError: Found a cycle

Hello! I am trying out dbt-core for the first time for a POC project. I am trying to do a very simple example, but I keep running into the same error and cannot find a solution from official documention. The same error appears whether I run dbt test on my source, or if I try to dbt run the model.
THis is the error:

/dbt/compilation.py", line 438, in link_graph
    raise RuntimeError("Found a cycle: {}".format(cycle))
RuntimeError: Found a cycle: model.wc_demo.wc_demo_model_1

Can I have help reviewing my following setup to see what mistake I am making?

I have a profile.yml setup in the default user .dbt folder, and connect to snowflake . (I ran dbt debug and connection looks okay)

Here’s the strucuture of my profile.yml:

wc_demo:
  outputs:
    dev:
      account: my_account_name
      database: MY_DB
      private_key_passphrase: password
      private_key_path: /path/to/my/keyfile
      role: MY_ROLE
      schema: MY_SCHEMA
      threads: 1
      type: snowflake
      user: MY_USER
      warehouse: MY_WHS
  target: dev

My directory structure looks like this:
image

Here’s my files defined:

dbt_project.yml


name: wc_demo
version: '1.0.0'
config-version: 2
profile: wc_demo
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"  
clean-targets: 
  - "target"
  - "dbt_packages"

models:
  wc_demo:
    demo:
      materialized: view

packages.yml

packages:

  - package: dbt-labs/metrics
    version: [">=1.3.0", "<1.4.0"]

packages:
  - package: dbt-labs/dbt_utils
    version: 0.9.2

models/sources/sources.yml

version: 2

sources:
  - name: wc_demo
    database: MY_DB
    schema: MY_SCHEMA
    freshness: # default freshness
      warn_after: {count: 12, period: hour}
      error_after: {count: 24, period: hour}
    loaded_at_field: SNAPSHOT_DATE
    description: HERES MY DESCRIPTION

    tables:
      - name: MY_TABLE_NAME
        description: >
          Here's a descripton of my table
        loaded_at_field: SNAPSHOT_DATE
        columns: 
           - name: uid
             description: primary key
             tests:
              - unique
              - not_null

models/demo/demo.yml

version: 2

models:
  - name: wc_demo_model_1
    description: first demo project
    config:
      enabled: true
    columns:
      - name: uid
        description: "The primary key for this table"
        tests:
          - unique
          - not_null

models/demo/wc_demo_model_1.sql

select uid
from MY_SCHEMA.MY_TABLE_NAME

Thank you!

1 Like

use ref

select uid
from MY_SCHEMA.MY_TABLE_NAME

to

select uid
FROM {{ source('wc_demo', 'MY_TABLE_NAME')}}

Hi @erin.valdes! Thanks for sharing so much context to help with the debugging.

It’s very strange that you’re seeing errors about a cycle, when you only have a single model. Normally you’d need multiple models to have a loop between them, and you’d need to be using source/ref to define those connections. As @obar1 said you should definitely use source() to access your table instead of hardcoding it in! That’s how dbt knows what order to build models in and can create the documentation site.

I’m on mobile right now so can’t test it, but I even wonder whether maybe dbt misbehaves if there are no references defined anywhere in the project? Would be a bit weird if it did, but I can’t think of another cause offhand.

Have you gone through our getting started project? It will step you through what’s involved in building a project from start to finish, and might be a good jumping off point: Getting started with dbt Core | dbt Developer Hub