From 2489771cdb52c29b23fbd0a29802b8f59ab57116 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 28 Sep 2023 18:44:22 +0100 Subject: [PATCH 1/2] fix double rendering of sql_header in dbt show --- core/dbt/include/global_project/macros/adapters/show.sql | 2 -- tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py | 6 ++++-- tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/dbt/include/global_project/macros/adapters/show.sql b/core/dbt/include/global_project/macros/adapters/show.sql index 2e23a919d29..33a93f3db9d 100644 --- a/core/dbt/include/global_project/macros/adapters/show.sql +++ b/core/dbt/include/global_project/macros/adapters/show.sql @@ -1,6 +1,4 @@ {% macro get_show_sql(compiled_code, sql_header, limit) -%} - {%- set sql_header = sql_header -%} - {{ sql_header if sql_header is not none }} {%- if sql_header -%} {{ sql_header }} {%- endif -%} diff --git a/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py b/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py index 6eda5a695f3..c5480ba16d2 100644 --- a/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py +++ b/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py @@ -1,8 +1,10 @@ models__sql_header = """ {% call set_sql_header(config) %} -set session time zone '{{ var("timezone", "Europe/Paris") }}'; +with _variables as ( + select 1 as my_variable +) {%- endcall %} -select current_setting('timezone') as timezone +select my_variable from _variables """ models__ephemeral_model = """ diff --git a/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py b/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py index a93bb9dd2ab..419485cf650 100644 --- a/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py +++ b/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py @@ -50,7 +50,6 @@ def models(self): } def test_sql_header(self, project): - run_dbt(["build", "--vars", "timezone: Asia/Kolkata"]) run_dbt(["show", "--select", "sql_header", "--vars", "timezone: Asia/Kolkata"]) From 795e2e1a0d713c7b8208e1d280349ecad6d02732 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 28 Sep 2023 18:49:08 +0100 Subject: [PATCH 2/2] changelog entry --- .changes/unreleased/Fixes-20230928-184856.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230928-184856.yaml diff --git a/.changes/unreleased/Fixes-20230928-184856.yaml b/.changes/unreleased/Fixes-20230928-184856.yaml new file mode 100644 index 00000000000..9f18fae5aeb --- /dev/null +++ b/.changes/unreleased/Fixes-20230928-184856.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: avoid double-rendering sql_header in dbt show +time: 2023-09-28T18:48:56.419428+01:00 +custom: + Author: michelleark + Issue: "8739"