Skip to content

Commit 630b422

Browse files
authored
Merge pull request #17 from get-select/handle_non_mappings_gracefully
Add warning when non-mapping query tag is set
2 parents bf3b513 + 589b4be commit 630b422

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

.changes/2.3.1.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## dbt-snowflake-query-tags 2.3.1 - August 18, 2023
2+
3+
### Features
4+
5+
- Handle non-mapping configs gracefully ([#17](https://github.com/get-select/dbt-snowflake-query-tags/pull/17))
6+
7+

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
66
and is generated by [Changie](https://github.com/miniscruff/changie).
77

8+
## dbt-snowflake-query-tags 2.3.1 - August 18, 2023
9+
10+
### Features
11+
12+
- Handle non-mapping configs gracefully ([#17](https://github.com/get-select/dbt-snowflake-query-tags/pull/17))
13+
14+
15+
816
## dbt-snowflake-query-tags 2.3.0 - June 29, 2023
917

1018
### Features

dbt_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name: 'dbt_snowflake_query_tags'
2-
version: '2.3.0'
2+
version: '2.3.1'
33
config-version: 2

integration_test_project/models/materialized_incremental.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{ config(materialized='incremental', tags=['a', 'b', 'c']) }}
1+
{{ config(materialized='incremental', tags=['a', 'b', 'c'], query_tag={'test': 'test'}) }}
22

33
select 1 as a
44

integration_test_project/models/materialized_table.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{{
22
config(
33
meta={
4-
"owner": "@alice",
4+
"owner": "@alice",
55
"model_maturity": "in dev"
66
},
77
materialized="table",
8-
tags='a'
8+
tags='a',
9+
query_tag="this will generate a warning"
910
)
1011
}}
1112

macros/query_tags.sql

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,37 @@
44

55
{% macro default__set_query_tag() -%}
66
{# Start with any model-configured dict #}
7-
{% set tag_dict = config.get('query_tag', default={}) %}
7+
{% set query_tag = config.get('query_tag', default={}) %}
88

9-
{%- do tag_dict.update(
9+
{% if query_tag is not mapping %}
10+
{% do log("dbt-snowflake-query-tags warning: the query_tag config value of '{}' is not a mapping type, so is being ignored. If you'd like to add additional query tag information, use a mapping type instead, or remove it to avoid this message.".format(query_tag), True) %}
11+
{% set query_tag = {} %} {# If the user has set the query tag config as a non mapping type, start fresh #}
12+
{% endif %}
13+
14+
15+
{%- do query_tag.update(
1016
app='dbt',
1117
dbt_snowflake_query_tags_version='2.3.0',
1218
) -%}
1319

1420
{% if thread_id %}
15-
{%- do tag_dict.update(
21+
{%- do query_tag.update(
1622
thread_id=thread_id
1723
) -%}
1824
{% endif %}
1925

2026

2127
{# We have to bring is_incremental through here because its not available in the comment context #}
2228
{% if model.resource_type == 'model' %}
23-
{%- do tag_dict.update(
29+
{%- do query_tag.update(
2430
is_incremental=is_incremental()
2531
) -%}
2632
{% endif %}
2733

28-
{% set new_query_tag = tojson(tag_dict) %}
34+
{% set query_tag_json = tojson(query_tag) %}
2935
{% set original_query_tag = get_current_query_tag() %}
30-
{{ log("Setting query_tag to '" ~ new_query_tag ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }}
31-
{% do run_query("alter session set query_tag = '{}'".format(new_query_tag)) %}
36+
{{ log("Setting query_tag to '" ~ query_tag_json ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }}
37+
{% do run_query("alter session set query_tag = '{}'".format(query_tag_json)) %}
3238
{{ return(original_query_tag)}}
3339
{% endmacro %}
3440

0 commit comments

Comments
 (0)