From 08624c911f3c25e2f92cdcbd3c9748c0380df356 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 28 Sep 2023 19:35:14 +0100 Subject: [PATCH] Fix: avoid double-rendering sql_header in dbt show (#8740) (cherry picked from commit 408a78985a647c52125e344c64747b21c02651f7) --- .changes/unreleased/Fixes-20230928-184856.yaml | 6 ++++++ 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 - 4 files changed, 10 insertions(+), 5 deletions(-) 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" 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"])