Skip to content

Commit

Permalink
fix: override materialization python models (#8538)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmessias authored Nov 14, 2024
1 parent 35c0920 commit 84230ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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 @@ -1005,7 +1005,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 @@ -1200,7 +1200,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

0 comments on commit 84230ce

Please sign in to comment.