Skip to content

Commit

Permalink
Limit data_tests warning to root_project
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Jun 27, 2024
1 parent 3c5fc6d commit e3ff145
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240627-154448.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Limit data_tests deprecation to root_project
time: 2024-06-27T15:44:48.579869-04:00
custom:
Author: gshank
Issue: "9835"
25 changes: 13 additions & 12 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def get_full_source_name(self):
def get_source_representation(self):
return f'source("{self.source.name}", "{self.table.name}")'

def validate_data_tests(self):
def validate_data_tests(self, is_root_project: bool):
"""
sources parse tests differently than models, so we need to do some validation
here where it's done in the PatchParser for other nodes
Expand All @@ -1131,11 +1131,12 @@ def validate_data_tests(self):
"Invalid test config: cannot have both 'tests' and 'data_tests' defined"
)
if self.tests:
deprecations.warn(
"project-test-config",
deprecated_path="tests",
exp_path="data_tests",
)
if is_root_project:
deprecations.warn(
"project-test-config",
deprecated_path="tests",
exp_path="data_tests",
)
self.data_tests.extend(self.tests)
self.tests.clear()

Expand All @@ -1146,11 +1147,12 @@ def validate_data_tests(self):
"Invalid test config: cannot have both 'tests' and 'data_tests' defined"
)
if column.tests:
deprecations.warn(
"project-test-config",
deprecated_path="tests",
exp_path="data_tests",
)
if is_root_project:
deprecations.warn(
"project-test-config",
deprecated_path="tests",
exp_path="data_tests",
)
column.data_tests.extend(column.tests)
column.tests.clear()

Expand All @@ -1168,7 +1170,6 @@ def columns(self) -> Sequence[UnparsedColumn]:
return [] if self.table.columns is None else self.table.columns

def get_tests(self) -> Iterator[Tuple[Dict[str, Any], Optional[UnparsedColumn]]]:
self.validate_data_tests()
for data_test in self.data_tests:
yield normalize_test(data_test), None

Expand Down
2 changes: 2 additions & 0 deletions core/dbt/parser/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def get_generic_test_parser_for(self, package_name: str) -> "SchemaGenericTestPa
return generic_test_parser

def get_source_tests(self, target: UnpatchedSourceDefinition) -> Iterable[GenericTestNode]:
is_root_project = True if self.root_project.project_name == target.package_name else False
target.validate_data_tests(is_root_project)
for data_test, column in target.get_tests():
yield self.parse_source_test(
target=target,
Expand Down

0 comments on commit e3ff145

Please sign in to comment.