From 84230ce33356990728507bd572d350e1aa960cfb Mon Sep 17 00:00:00 2001 From: bruno messias Date: Thu, 14 Nov 2024 15:31:23 -0300 Subject: [PATCH] fix: override materialization python models (#8538) --- .changes/unreleased/Fixes-20241002-142638.yaml | 6 ++++++ core/dbt/parser/base.py | 10 +++++++++- tests/unit/parser/test_parser.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Fixes-20241002-142638.yaml diff --git a/.changes/unreleased/Fixes-20241002-142638.yaml b/.changes/unreleased/Fixes-20241002-142638.yaml new file mode 100644 index 00000000000..6ad7dba6502 --- /dev/null +++ b/.changes/unreleased/Fixes-20241002-142638.yaml @@ -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" diff --git a/core/dbt/parser/base.py b/core/dbt/parser/base.py index 32dbe6dedab..1d27947a25f 100644 --- a/core/dbt/parser/base.py +++ b/core/dbt/parser/base.py @@ -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 @@ -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 diff --git a/tests/unit/parser/test_parser.py b/tests/unit/parser/test_parser.py index d5f809252b3..8894e47ce84 100644 --- a/tests/unit/parser/test_parser.py +++ b/tests/unit/parser/test_parser.py @@ -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]) """ @@ -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):