From d1a49d3128e21131cd93b37ecad0b244461a36b3 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Fri, 30 Aug 2019 15:48:17 -0400 Subject: [PATCH] (#1717) fix for re-rendering in statement calls --- core/dbt/include/global_project/macros/core.sql | 4 ++-- .../global_project/macros/materializations/helpers.sql | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/dbt/include/global_project/macros/core.sql b/core/dbt/include/global_project/macros/core.sql index a152cd76cec..5051c5cb062 100644 --- a/core/dbt/include/global_project/macros/core.sql +++ b/core/dbt/include/global_project/macros/core.sql @@ -1,6 +1,6 @@ {% macro statement(name=None, fetch_result=False, auto_begin=True) -%} {%- if execute: -%} - {%- set sql = render(caller()) -%} + {%- set sql = caller() -%} {%- if name == 'main' -%} {{ log('Writing runtime SQL for node "{}"'.format(model['unique_id'])) }} @@ -16,7 +16,7 @@ {%- endmacro %} {% macro noop_statement(name=None, status=None, res=None) -%} - {%- set sql = render(caller()) -%} + {%- set sql = caller() -%} {%- if name == 'main' -%} {{ log('Writing runtime SQL for node "{}"'.format(model['unique_id'])) }} diff --git a/core/dbt/include/global_project/macros/materializations/helpers.sql b/core/dbt/include/global_project/macros/materializations/helpers.sql index da78eb93506..dc21ac5d3ba 100644 --- a/core/dbt/include/global_project/macros/materializations/helpers.sql +++ b/core/dbt/include/global_project/macros/materializations/helpers.sql @@ -5,9 +5,12 @@ commit; {% endcall %} {% endif %} - {% call statement(auto_begin=inside_transaction) %} - {{ hook.get('sql') }} - {% endcall %} + {% set rendered = render(hook.get('sql')) | trim %} + {% if (rendered | length) > 0 %} + {% call statement(auto_begin=inside_transaction) %} + {{ rendered }} + {% endcall %} + {% endif %} {% endfor %} {% endmacro %}