Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query tag back to incremental models #1212

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

{% materialization incremental, adapter='snowflake', supported_languages=['sql', 'python'] -%}

{% set original_query_tag = set_query_tag() %}

{#-- Set vars --#}
{%- set full_refresh_mode = (should_full_refresh()) -%}
Expand Down
34 changes: 13 additions & 21 deletions tests/functional/query_tag/test_query_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from dbt.tests.util import run_dbt


snapshots__snapshot_query_tag_sql = """
{% snapshot snapshot_query_tag %}
{{
Expand All @@ -14,16 +15,15 @@
}}
select 1 as id, 'blue' as color
{% endsnapshot %}

"""


models__table_model_query_tag_sql = """
{{ config(materialized = 'table') }}

select 1 as id

"""


models__models_config_yml = """
version: 2

Expand All @@ -33,23 +33,21 @@
- name: id
data_tests:
- unique

"""


models__view_model_query_tag_sql = """
{{ config(materialized = 'view') }}

select 1 as id

"""


models__incremental_model_query_tag_sql = """
{{ config(materialized = 'incremental', unique_key = 'id') }}

select 1 as id

"""


macros__check_tag_sql = """
{% macro check_query_tag() %}

Expand All @@ -61,12 +59,12 @@
{% endif %}

{% endmacro %}

"""


seeds__seed_query_tag_csv = """id
1
"""
""".strip()


class TestQueryTag:
Expand Down Expand Up @@ -95,20 +93,14 @@ def seeds(self):
def project_config_update(self, prefix):
return {
"config-version": 2,
"models": {
"tests": {"query_tag": prefix, "post-hook": "{{ check_tag() }}"},
},
"seeds": {
"tests": {"query_tag": prefix, "post-hook": "{{ check_tag() }}"},
},
"snapshots": {
"tests": {"query_tag": prefix, "post-hook": "{{ check_tag() }}"},
},
"models": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the successful runs, they warn that models.tests, seeds.tests, and snapshots.tests were unused configuration paths. In other words, the post-hook never ran. We also know that since the post-hook references a macro that does not exist; it should have referenced check_query_tag instead of check_tag.

"seeds": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"},
"snapshots": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"},
"tests": {"test": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"}},
}

def build_all_with_query_tags(self, project, prefix):
run_dbt(["build", "--vars", '{{"check_tag": "{}"}}'.format(prefix)])
run_dbt(["build", "--vars", '{{"query_tag": "{}"}}'.format(prefix)])

def test_snowflake_query_tag(self, project, prefix):
self.build_all_with_query_tags(project, prefix)
Expand All @@ -130,7 +122,7 @@ def profiles_config_update(self, prefix):
return {"query_tag": prefix}

def build_all_with_query_tags(self, project, prefix):
run_dbt(["build", "--vars", '{{"check_tag": "{}"}}'.format(prefix)])
run_dbt(["build", "--vars", '{{"query_tag": "{}"}}'.format(prefix)])

def test_snowflake_query_tag(self, project, prefix):
self.build_all_with_query_tags(project, prefix)
Expand Down
Loading