Skip to content

Commit

Permalink
Fix post_model_hook in data and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Oct 2, 2024
1 parent 7940ad5 commit c6e44db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from contextlib import nullcontext
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional, Set
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set

import dbt.exceptions
import dbt_common.exceptions.base
Expand Down Expand Up @@ -46,6 +46,9 @@
from dbt_common.events.functions import fire_event
from dbt_common.exceptions import DbtInternalError, DbtRuntimeError, NotImplementedError

if TYPE_CHECKING:
from dbt.adapters.base import BaseAdapter


def read_profiles(profiles_dir: Optional[str] = None) -> Dict[str, Any]:
"""This is only used for some error handling"""
Expand Down Expand Up @@ -167,7 +170,7 @@ def __init__(self, node) -> None:


class BaseRunner(metaclass=ABCMeta):
def __init__(self, config, adapter, node, node_index: int, num_nodes: int) -> None:
def __init__(self, config, adapter: BaseAdapter, node, node_index: int, num_nodes: int) -> None:
self.config = config
self.compiler = Compiler(config)
self.adapter = adapter
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def _execute_microbatch_model(
else:
return self._build_run_model_result(model, context)

def execute(self, model, manifest):
def execute(self, model: ModelNode, manifest: Manifest):
context = generate_runtime_model_context(model, self.config, manifest)

materialization_macro = manifest.find_materialization_macro_by_name(
Expand Down
8 changes: 6 additions & 2 deletions core/dbt/task/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ def execute_data_test(self, data_test: TestNode, manifest: Manifest) -> TestResu
"Invalid materialization context generated, missing config: {}".format(context)
)

context_config = context["config"]

# generate materialization macro
macro_func = MacroGenerator(materialization_macro, context)
try:
# execute materialization macro
macro_func()
finally:
self.adapter.post_model_hook(context, hook_ctx)
self.adapter.post_model_hook(context_config, hook_ctx)

# load results from context
# could eventually be returned directly by materialization
Expand Down Expand Up @@ -238,6 +240,8 @@ def execute_unit_test(
"Invalid materialization context generated, missing config: {}".format(context)
)

context_config = context["config"]

# generate materialization macro
macro_func = MacroGenerator(materialization_macro, context)
try:
Expand All @@ -249,7 +253,7 @@ def execute_unit_test(
f"There may be an error in the unit test definition: check the data types.\n {e}"
)
finally:
self.adapter.post_model_hook(context, hook_ctx)
self.adapter.post_model_hook(context_config, hook_ctx)

# load results from context
# could eventually be returned directly by materialization
Expand Down

0 comments on commit c6e44db

Please sign in to comment.