From 6a9e35ae9fee69bf012a5dcfda4d80c4cbd63ec1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:51:33 -0500 Subject: [PATCH] Fix for dbt_project.yml "tests" config resulting in incorrect state:modified (#11166) (#11169) (cherry picked from commit bf18b5984597c84b0ac8ccf6ef62cb0bed039689) Co-authored-by: Gerda Shank --- .../unreleased/Fixes-20241218-112640.yaml | 6 +++ core/dbt/config/project.py | 3 ++ .../defer_state/test_unrendered_config.py | 45 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .changes/unreleased/Fixes-20241218-112640.yaml create mode 100644 tests/functional/defer_state/test_unrendered_config.py diff --git a/.changes/unreleased/Fixes-20241218-112640.yaml b/.changes/unreleased/Fixes-20241218-112640.yaml new file mode 100644 index 00000000000..38a72bc867a --- /dev/null +++ b/.changes/unreleased/Fixes-20241218-112640.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix unrendered_config for tests from dbt_project.yml +time: 2024-12-18T11:26:40.270022-05:00 +custom: + Author: gshank + Issue: "11146" diff --git a/core/dbt/config/project.py b/core/dbt/config/project.py index cbad5a38434..1054c42041d 100644 --- a/core/dbt/config/project.py +++ b/core/dbt/config/project.py @@ -199,6 +199,9 @@ def load_raw_project(project_root: str) -> Dict[str, Any]: if not isinstance(project_dict, dict): raise DbtProjectError(f"{DBT_PROJECT_FILE_NAME} does not parse to a dictionary") + if "tests" in project_dict and "data_tests" not in project_dict: + project_dict["data_tests"] = project_dict.pop("tests") + return project_dict diff --git a/tests/functional/defer_state/test_unrendered_config.py b/tests/functional/defer_state/test_unrendered_config.py new file mode 100644 index 00000000000..958f2a6d6c9 --- /dev/null +++ b/tests/functional/defer_state/test_unrendered_config.py @@ -0,0 +1,45 @@ +import pytest + +from dbt.tests.util import run_dbt + +dbt_project_update = """ +models: + my_dbt_project: + +materialized: table + +tests: + +store_failures: true +""" + +foo_sql = """ +select 1 as id +""" + +schema_yml = """ +models: + - name: foo + columns: + - name: id + tests: + - unique +""" + + +class TestGenericTestUnrenderedConfig: + @pytest.fixture(scope="class") + def project_config_update(self): + return dbt_project_update + + @pytest.fixture(scope="class") + def models(self): + return { + "foo.sql": foo_sql, + "schema.yml": schema_yml, + } + + def test_unrendered_config(self, project): + manifest = run_dbt(["parse"]) + assert manifest + test_node_id = "test.test.unique_foo_id.fa8c520a2e" + test_node = manifest.nodes[test_node_id] + assert test_node.unrendered_config == {"store_failures": True}