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

fix: override materialization python models #8538

Merged
Merged
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241002-142638.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: ' override materialization python models'
time: 2024-10-02T14:26:38.332191458-03:00
custom:
Author: devmessias
Issue: "8520"
10 changes: 9 additions & 1 deletion core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def _create_parsetime_node(
name = block.name
if block.path.relative_path.endswith(".py"):
language = ModelLanguage.python
config.add_config_call({"materialized": "table"})
else:
# this is not ideal but we have a lot of tests to adjust if don't do it
language = ModelLanguage.sql
Expand Down Expand Up @@ -322,6 +321,15 @@ def update_parsed_node_config(
# build_config_dict takes the config_call_dict in the ContextConfig object
# and calls calculate_node_config to combine dbt_project configs and
# config calls from SQL files, plus patch configs (from schema files)
# This normalize the config for a model node due #8520; should be improved latter
if not patch_config_dict:
patch_config_dict = {}
if (
parsed_node.resource_type == NodeType.Model
and parsed_node.language == ModelLanguage.python
):
if "materialized" not in patch_config_dict:
patch_config_dict["materialized"] = "table"
config_dict = config.build_config_dict(patch_config_dict=patch_config_dict)

# Set tags on node provided in config blocks. Tags are additive, so even if
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ def model(dbt, session):
import pandas as pd

def model(dbt, session):
dbt.config(materialized="view")
dbt.config(materialized="incremental")
return pd.dataframe([1, 2])
"""

Expand Down Expand Up @@ -1199,7 +1199,7 @@ def test_python_model_custom_materialization(self):
self.parser.manifest.files[block.file.file_id] = block.file
self.parser.parse_file(block)
node = list(self.parser.manifest.nodes.values())[0]
self.assertEqual(node.get_materialization(), "view")
self.assertEqual(node.get_materialization(), "incremental")


class StaticModelParserTest(BaseParserTest):
Expand Down