You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the unique test is overriden within a project, it follows that the variable primary_key_test_macros should be explicitly declared in the project.yml, specifying the project's own test version instead of the builtin (because our test will otherwise not be considered to cover unique key testing).
Since int_all_graph_resources is composing a list of tests from the primary_key_test_macros variable, our version of unique will be included.
However, right after the test list is composed, the line
{%- do test_macro_list.append("dbt.test_unique") -%}
adds the builtin version of unique to the list, which leads the block
{% for test in test_macro_set %}unioned_with_calc.macro_dependencies like '%macro.{{ test }}%' and unioned_with_calc.resource_type = 'test' as is_{{ test.split('.')[1] }}
to cause a name collision, since both our_project.test_unique and dbt.test_unique return the same value after test.split('.')[1].
Steps to reproduce
In a dbt project (let's use jaffle-shop-classic as an example), install the dbt_project_evaluator package, and run it
dbt run -s package:dbt_project_evaluator
to ensure that it is working properly.
Create a custom version of the unique test as jaffle-shop-classic/tests/test_unique.sql, such as:
{% test unique(model, column_name) %}{{ config(severity = 'warn') }}select{{ column_name }} as unique_field,count(*) as n_recordsfrom {{ model }}where `{{ column_name }}`is not nullgroup by `{{ column_name }}`having count(*) > 1{% endtest %}
The removal of that line produces identical int_all_graph_resources models, both in jaffle-shop-classic run locally on PostgreSQL, as in our production datawarehouse running on BigQuery.
I have opened a PR with a fix, which tries to maintain my best guess of the intended functionality of the line.
Describe the bug
If the
unique
test is overriden within a project, it follows that the variableprimary_key_test_macros
should be explicitly declared in the project.yml, specifying the project's own test version instead of the builtin (because our test will otherwise not be considered to cover unique key testing).Since
int_all_graph_resources
is composing a list of tests from theprimary_key_test_macros
variable, our version ofunique
will be included.However, right after the test list is composed, the line
{%- do test_macro_list.append("dbt.test_unique") -%}
adds the builtin version of
unique
to the list, which leads the blockto cause a name collision, since both
our_project.test_unique
anddbt.test_unique
return the same value aftertest.split('.')[1]
.Steps to reproduce
In a dbt project (let's use jaffle-shop-classic as an example), install the dbt_project_evaluator package, and run it
to ensure that it is working properly.
Create a custom version of the
unique
test asjaffle-shop-classic/tests/test_unique.sql
, such as:and add the variable
to your
dbt_project.yml
.Run
Expected results
The package builds its models and the results are leveraging our custom test instead of the built-in one.
Actual results
We receive a
because
int_all_graph_resources
is appending the builtinunique
test to thetest_macro_list
, causing a name collision with our test.System information
Which database are you using dbt with?
The output of
dbt --version
:Additional context
The problem does not reproduce if we override other tests (such as
not_null
), or if the{%- do test_macro_list.append("dbt.test_unique") -%}
line is removed.
Are you interested in contributing the fix?
UPDATE: a PR has been submitted!
The text was updated successfully, but these errors were encountered: