From fcebd6813537390a6ab8c2c0f684755a706d1f86 Mon Sep 17 00:00:00 2001 From: Pfitzn Date: Thu, 19 Sep 2024 13:45:08 +0200 Subject: [PATCH 1/2] Removed line that adds the built-in unique test to the "primary_key_test_macros" list in order to avoid name collisions on unique test definition overrides --- models/marts/core/int_all_graph_resources.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/models/marts/core/int_all_graph_resources.sql b/models/marts/core/int_all_graph_resources.sql index 01681444..d8a54f3f 100644 --- a/models/marts/core/int_all_graph_resources.sql +++ b/models/marts/core/int_all_graph_resources.sql @@ -7,7 +7,9 @@ {%- do test_macro_list.append(test) -%} {%- endfor %} {%- endfor -%} -{%- do test_macro_list.append("dbt.test_unique") -%} +{%- if test_macro_list | length == 0 -%} + {%- do test_macro_list.append("dbt.test_unique") -%} +{%- endif -%} {%- set test_macro_set = set_strict(test_macro_list) -%} {%- set quoted_directory_pattern = wrap_string_with_quotes(get_directory_pattern()) %} From f066a8d5962b9033d6540868e1c86338301fdaa5 Mon Sep 17 00:00:00 2001 From: Pfitzn Date: Thu, 19 Sep 2024 14:59:13 +0200 Subject: [PATCH 2/2] Add built-in unique test if no preexisting test matches its name. --- models/marts/core/int_all_graph_resources.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/marts/core/int_all_graph_resources.sql b/models/marts/core/int_all_graph_resources.sql index d8a54f3f..1d3534c4 100644 --- a/models/marts/core/int_all_graph_resources.sql +++ b/models/marts/core/int_all_graph_resources.sql @@ -2,12 +2,16 @@ {# flatten the sets of permissable primary key test sets to one level for later iteration #} {%- set test_macro_list = [] %} +{%- set test_macro_names_list = [] %} {%- for test_set in var('primary_key_test_macros') -%} {%- for test in test_set %} - {%- do test_macro_list.append(test) -%} + {%- do test_macro_list.append(test) -%} {%- endfor %} {%- endfor -%} -{%- if test_macro_list | length == 0 -%} +{% for test in test_macro_list %} + {%- do test_macro_names_list.append(test.split('.')[1]) -%} +{%- endfor -%} +{%- if "test_unique" not in test_macro_names_list -%} {%- do test_macro_list.append("dbt.test_unique") -%} {%- endif -%} {%- set test_macro_set = set_strict(test_macro_list) -%}