From f9e2310d9fbb4ddb9d7a43c0a9962652742262c9 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 20 Jul 2023 16:51:18 -0700 Subject: [PATCH 1/3] Add test asserting that a macro with the work materializtion doesn't cause issues --- tests/functional/macros/fixtures.py | 12 ++++++++++++ tests/functional/macros/test_macros.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/functional/macros/fixtures.py b/tests/functional/macros/fixtures.py index 500859ec1f3..77de40951f8 100644 --- a/tests/functional/macros/fixtures.py +++ b/tests/functional/macros/fixtures.py @@ -4,6 +4,12 @@ }} """ +models__materialization_macro = """ +{{ + materialization_macro() +}} +""" + models__with_undefined_macro = """ {{ dispatch_to_nowhere() }} select 1 as id @@ -75,6 +81,12 @@ {% endmacro %} """ +macros__named_materialization = """ +{% macro materialization_macro() %} + select 1 as foo +{% endmacro %} +""" + macros__no_default_macros = """ {% macro do_something2(foo2, bar2) %} diff --git a/tests/functional/macros/test_macros.py b/tests/functional/macros/test_macros.py index 31f7647434d..a93a7d76c85 100644 --- a/tests/functional/macros/test_macros.py +++ b/tests/functional/macros/test_macros.py @@ -20,12 +20,14 @@ models__override_get_columns_macros, models__deprecated_adapter_macro_model, models__incorrect_dispatch, + models__materialization_macro, macros__my_macros, macros__no_default_macros, macros__override_get_columns_macros, macros__package_override_get_columns_macros, macros__deprecated_adapter_macro, macros__incorrect_dispatch, + macros__named_materialization, ) @@ -78,6 +80,21 @@ def test_working_macros(self, project): check_relations_equal(project.adapter, ["expected_local_macro", "local_macro"]) +class TestMacrosNamedMaterialization: + @pytest.fixture(scope="class") + def models(self): + return { + "models_materialization_macro.sql": models__materialization_macro, + } + + @pytest.fixture(scope="class") + def macros(self): + return {"macros_named_materialization.sql": macros__named_materialization} + + def test_macro_with_materialization_in_name_works(self, project): + run_dbt(expect_pass=True) + + class TestInvalidMacros: @pytest.fixture(scope="class") def models(self): From 695f0073a0eb4152bdfd8945988e369dd70f437c Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 20 Jul 2023 16:57:07 -0700 Subject: [PATCH 2/3] Let macro names include the word `materialization` Previously we were checking if a macro included a materialization based on if the macro name included the word `materialization`. However, a macro name included the word `materialization` isn't guarnteed to actually have a materialization, and a macro that doesn't have `materialization` in the name isn't guaranteed to not have a materialization. This change is to detect macros with materializations based on the detected block type of the macro. --- core/dbt/parser/macros.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/parser/macros.py b/core/dbt/parser/macros.py index a7c1f2af05c..7178222fc1d 100644 --- a/core/dbt/parser/macros.py +++ b/core/dbt/parser/macros.py @@ -81,7 +81,7 @@ def parse_unparsed_macros(self, base_node: UnparsedMacro) -> Iterable[Macro]: name: str = macro.name.replace(MACRO_PREFIX, "") node = self.parse_macro(block, base_node, name) # get supported_languages for materialization macro - if "materialization" in name: + if block.block_type_name == "materialization": node.supported_languages = jinja.get_supported_languages(macro) yield node From 4e2f076f369b0c6ad978611c13adada994f92f9f Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 20 Jul 2023 17:01:39 -0700 Subject: [PATCH 3/3] Add changie doc materialization in macro detection --- .changes/unreleased/Fixes-20230720-170112.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230720-170112.yaml diff --git a/.changes/unreleased/Fixes-20230720-170112.yaml b/.changes/unreleased/Fixes-20230720-170112.yaml new file mode 100644 index 00000000000..9947afceafe --- /dev/null +++ b/.changes/unreleased/Fixes-20230720-170112.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Stop detecting materialization macros based on macro name +time: 2023-07-20T17:01:12.496238-07:00 +custom: + Author: QMalcolm + Issue: "6231"