Skip to content

Commit 930ee9a

Browse files
committed
Extend to snapshots without 'snapshot' in name
1 parent 96cb380 commit 930ee9a

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

macros/run_end/save_results_history.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040

4141
{% if any_refs %}
4242
{% set name = any_refs[0] %}
43-
-- NOTE: This relies on snapshot models to include the word "snapshot" in the model name.
44-
-- There doesn't seem to be an easily accessible field to tell us that this node is a snapshot
45-
-- without relying on the name or other proxies.
46-
{% if "snapshot" in name %}
43+
-- NOTE: This relies on snapshot models to include the word "snapshot" in the model name or
44+
-- the column `dbt_scd_id` to be included in the metadata kwargs (since this is a good proxy
45+
-- for this model being a snapshot given `dbt_scd_id` is an internal dbt field).
46+
-- There doesn't seem to be another, easily accessible field to tell us unambigously that this node is a snapshot
47+
{% set metadata_column_name = el.node.to_dict().get('test_metadata', dict()).get('kwargs', dict()).get('column_name') %}
48+
{% if "snapshot" in name or metadata_column_name == "dbt_scd_id" %}
4749
{% set ref_type = "snapshot" %}
4850
{% else %}
4951
{% set ref_type = "model" %}

0 commit comments

Comments
 (0)