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 47da473
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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
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"]

Check warning on line 162 in core/dbt/task/test.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/test.py#L162

Added line #L162 was not covered by tests

# 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)

Check warning on line 170 in core/dbt/task/test.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/test.py#L170

Added line #L170 was not covered by tests

# 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"]

Check warning on line 243 in core/dbt/task/test.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/test.py#L243

Added line #L243 was not covered by tests

# 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)

Check warning on line 256 in core/dbt/task/test.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/test.py#L256

Added line #L256 was not covered by tests

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

0 comments on commit 47da473

Please sign in to comment.