From e3ff1453b21a7719311d33c5c41725d0805f0bb9 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Thu, 27 Jun 2024 15:45:29 -0400 Subject: [PATCH] Limit data_tests warning to root_project --- .../unreleased/Fixes-20240627-154448.yaml | 6 +++++ core/dbt/contracts/graph/nodes.py | 25 ++++++++++--------- core/dbt/parser/sources.py | 2 ++ 3 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 .changes/unreleased/Fixes-20240627-154448.yaml diff --git a/.changes/unreleased/Fixes-20240627-154448.yaml b/.changes/unreleased/Fixes-20240627-154448.yaml new file mode 100644 index 00000000000..f2ea7dd739c --- /dev/null +++ b/.changes/unreleased/Fixes-20240627-154448.yaml @@ -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" diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index 328da2e04b0..338cb39b94e 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -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 @@ -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() @@ -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() @@ -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 diff --git a/core/dbt/parser/sources.py b/core/dbt/parser/sources.py index 5666a44da11..68dbed94ce5 100644 --- a/core/dbt/parser/sources.py +++ b/core/dbt/parser/sources.py @@ -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,