Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-1483] Backport #8181 to 1.6.latest #8196

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230720-170112.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion core/dbt/parser/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions tests/functional/macros/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
}}
"""

models__materialization_macro = """
{{
materialization_macro()
}}
"""

models__with_undefined_macro = """
{{ dispatch_to_nowhere() }}
select 1 as id
Expand Down Expand Up @@ -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) %}

Expand Down
17 changes: 17 additions & 0 deletions tests/functional/macros/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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):
Expand Down