Skip to content

Commit

Permalink
Fix #9608: Unit test fixture compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Mar 22, 2024
1 parent 2c1926c commit 68c7cb4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
10 changes: 3 additions & 7 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from dataclasses import dataclass, field
import hashlib
from pathlib import Path

from mashumaro.types import SerializableType
from typing import (
Expand Down Expand Up @@ -954,15 +955,10 @@ class UnitTestDefinition(NodeInfoMixin, GraphNode, UnitTestDefinitionResource):
def resource_class(cls) -> Type[UnitTestDefinitionResource]:
return UnitTestDefinitionResource

@property
def build_path(self):
# TODO: is this actually necessary?
return self.original_file_path

@property
def compiled_path(self):
# TODO: is this actually necessary?
return self.original_file_path
path = Path(self.original_file_path).parent / (self.name + ".sql")
return str(self.original_file_path / path)

@property
def depends_on_nodes(self):
Expand Down
5 changes: 3 additions & 2 deletions core/dbt/parser/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def parse_unit_test_case(self, test_case: UnitTestDefinition):

common_fields = {
"resource_type": NodeType.Model,
"original_file_path": original_input_node.original_file_path,
"original_file_path": unit_test_node.original_file_path,
"config": ModelConfig(materialized="ephemeral"),
"database": original_input_node.database,
"alias": original_input_node.identifier,
Expand All @@ -144,7 +144,8 @@ def parse_unit_test_case(self, test_case: UnitTestDefinition):
package_name=original_input_node.package_name,
unique_id=f"model.{original_input_node.package_name}.{input_name}",
name=input_name,
path=original_input_node.path or f"{input_name}.sql",
# models/my_model.yml/models/my_unit_test.sql
path=os.path.join(unit_test_node.original_file_path, unit_test_node.path),
)
if (
original_input_node.resource_type == NodeType.Model
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/task/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def print_run_result_error(result, newline: bool = True, is_warning: bool = Fals
else:
fire_event(RunResultErrorNoMessage(status=result.status))

if result.node.build_path is not None:
if result.node.compiled_path is not None:
with TextOnly():
fire_event(Formatting(""))
fire_event(SQLCompiledPath(path=result.node.compiled_path))
Expand Down

0 comments on commit 68c7cb4

Please sign in to comment.