Skip to content

Commit

Permalink
fix: change view materialization to table in python models
Browse files Browse the repository at this point in the history
See dbt-labs#8538 discussion for more details
  • Loading branch information
devmessias committed Oct 2, 2024
1 parent abb75b3 commit fff0850
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 0 additions & 6 deletions core/dbt/context/context_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def calculate_node_config(
) -> BaseConfig:
own_config = self.get_node_project(project_name)
result = self.initial_result(resource_type=resource_type, base=base)
if "_dbt_node_type_configs" in config_call_dict:
result = self._update_from_config(result, config_call_dict["_dbt_node_type_configs"])

project_configs = self._project_configs(own_config, fqn, resource_type)
for fqn_config in project_configs:
Expand All @@ -163,9 +161,6 @@ def calculate_node_config(

# config_calls are created in the 'experimental' model parser and
# the ParseConfigObject (via add_config_call)
config_call_dict = {
k: config_call_dict[k] for k in config_call_dict.keys() - {"_dbt_node_type_configs"}
}
result = self._update_from_config(result, config_call_dict)

if own_config.project_name != self._active_project.project_name:
Expand Down Expand Up @@ -197,7 +192,6 @@ def get_config_source(self, project: Project) -> ConfigSource:

def initial_result(self, resource_type: NodeType, base: bool) -> C:
# defaults, own_config, config calls, active_config (if != own_config)
# aqui vai puxar o node config com default view
config_cls = get_config_for(resource_type, base=base)
# Calculate the defaults. We don't want to validate the defaults,
# because it might be invalid in the case of required config members
Expand Down
22 changes: 17 additions & 5 deletions core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ def _create_parsetime_node(
name = block.name
if block.path.relative_path.endswith(".py"):
language = ModelLanguage.python
config.add_config_call(
{
"_dbt_node_type_configs": {"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 @@ -310,6 +305,22 @@ def update_parsed_node_relation_names(

self._update_node_relation_name(parsed_node)

def normalize_model_node(sellf, parsed_node: IntermediateNode) -> None:
"""This normalize the config for a model node.
The default materialization for a model is a view, but it's not
supported by python models. This function changes the default view to
table for python models.
"""
if not parsed_node.resource_type == NodeType.Model:
return None

if not parsed_node.language == ModelLanguage.python:
return None

if parsed_node.config.materialized == "view":
parsed_node.config.materialized = "table"

def update_parsed_node_config(
self,
parsed_node: FinalNode,
Expand All @@ -327,6 +338,7 @@ def update_parsed_node_config(
# and calls calculate_node_config to combine dbt_project configs and
# config calls from SQL files, plus patch configs (from schema files)
config_dict = config.build_config_dict(patch_config_dict=patch_config_dict)
self.normalize_model_node(parsed_node)

# Set tags on node provided in config blocks. Tags are additive, so even if
# config has been built before, we don't have to reset tags in the parsed_node.
Expand Down
1 change: 0 additions & 1 deletion tests/unit/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,6 @@ def test_python_model_parse(self):
config_call_dict={
"materialized": "table",
"packages": python_packages,
"_dbt_node_type_configs": {"materialized": "table"},
},
refs=[
RefArgs(name="a_model"),
Expand Down

0 comments on commit fff0850

Please sign in to comment.