referring current model

Hello All,

I have a table orders and iam using snapshot to build the data change history.I am using dbt utils macro to filter column names to generate surrogate key.

Iam generating surrogate key orders_surrogate_key will all columns expect unique column(orders_id)
The model is as below.

{% snapshot orders %}
“field”: “file_created_date”,
“data_type”: “date”,
“granularity”: “day”
) }}

orders_surrogate_key_cols=dbt_utils.get_filtered_columns_in_relation(from=ref(‘orders’), except=[“order_id”])

{{ generate_key(orders_surrogate_key_cols) }}
as orders_surrogate_key
from {{ ref(‘stg_orders’) }}

{% endsnapshot %}

When i try to run the model i gives me below error:
File “/opt/homebrew/Cellar/dbt-bigquery/1.2.0/libexec/lib/python3.9/site-packages/dbt/task/”, line 89, in compile_manifest
self.graph = compiler.compile(self.manifest)
File “/opt/homebrew/Cellar/dbt-bigquery/1.2.0/libexec/lib/python3.9/site-packages/dbt/”, line 480, in compile
self.link_graph(linker, manifest, add_test_edges)
File “/opt/homebrew/Cellar/dbt-bigquery/1.2.0/libexec/lib/python3.9/site-packages/dbt/”, line 418, in link_graph
** raise RuntimeError(“Found a cycle: {}”.format(cycle))**
RuntimeError: Found a cycle: snapshot.dbt_project.orders
07:42:51 Encountered an error:
Found a cycle: snapshot.dbt_project.orders

I tried to use {{this }}
orders_surrogate_key_cols=dbt_utils.get_filtered_columns_in_relation(from={{this}}, except=[“order_id”])
is giving different error:

Please let to know how to refer the current models to be passed in dbt.utils.macros for eg:get_filtered_columns_in_relation

Thanks in advance
Minhaj Pasha

Create a view model that comes before the snapshot that contains the orders_surrogate_key

1 Like