From 99355a6602ea5908b358b1b875f6553d46492cd0 Mon Sep 17 00:00:00 2001 From: Tom Phillips Date: Tue, 24 Sep 2024 13:57:20 +0100 Subject: [PATCH 1/4] Pull meta from config through to test result logs --- core/dbt/parser/schema_generic_tests.py | 1 + tests/functional/logging/test_logging.py | 27 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/core/dbt/parser/schema_generic_tests.py b/core/dbt/parser/schema_generic_tests.py index 14e2dbc862a..1200d2c6723 100644 --- a/core/dbt/parser/schema_generic_tests.py +++ b/core/dbt/parser/schema_generic_tests.py @@ -134,6 +134,7 @@ def get_hashable_md(data: Union[str, int, float, List, Dict]) -> Union[str, List "column_name": column_name, "checksum": FileHash.empty().to_dict(omit_none=True), "file_key_name": file_key_name, + "meta": target.config.get('meta', {}) if hasattr(target, 'config') else {}, } try: GenericTestNode.validate(dct) diff --git a/tests/functional/logging/test_logging.py b/tests/functional/logging/test_logging.py index e29bd9c7cac..29029b085af 100644 --- a/tests/functional/logging/test_logging.py +++ b/tests/functional/logging/test_logging.py @@ -277,3 +277,30 @@ def test_node_info_on_results(self, project, logs_dir): run_result_warning_count += 1 assert run_result_warning_count == 1 + + +class TestRunResultMeta: + @pytest.fixture(scope="class") + def models(self): + model_config = """ + models: + - name: my_model + meta: + owner: analytics + columns: + - name: id + tests: + - not_null + """ + return {"my_model.sql": "select null as id", "models.yml": model_config} + + def test_test_failures_include_meta_from_model_config(self, project, logs_dir): + results = run_dbt(["--log-format=json", "build"], expect_pass=False) + assert len(results) == 2 + + log_file = read_file(logs_dir, "dbt.log") + messages = [json.loads(line) for line in log_file.split("\n") if line] + [ + test_result, + ] = [message for message in messages if message["info"]["name"] == "LogTestResult"] + assert test_result["data"]["node_info"]["meta"] == {"owner": "analytics"} From f3e955ffe09aad83b931f9e7c0bd0899fb17a645 Mon Sep 17 00:00:00 2001 From: Tom Phillips Date: Wed, 2 Oct 2024 16:16:53 +0100 Subject: [PATCH 2/4] Add changelog entry --- .changes/unreleased/Fixes-20241002-155726.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20241002-155726.yaml diff --git a/.changes/unreleased/Fixes-20241002-155726.yaml b/.changes/unreleased/Fixes-20241002-155726.yaml new file mode 100644 index 00000000000..0dac56d5999 --- /dev/null +++ b/.changes/unreleased/Fixes-20241002-155726.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix missing meta config in test log messages +time: 2024-10-02T15:57:26.594034+01:00 +custom: + Author: tomwphillips + Issue: "10811" From c9190c60ef946f6256ddbfabb6726f8c67471045 Mon Sep 17 00:00:00 2001 From: Tom Phillips Date: Thu, 3 Oct 2024 11:41:50 +0100 Subject: [PATCH 3/4] Formatting --- core/dbt/parser/schema_generic_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/parser/schema_generic_tests.py b/core/dbt/parser/schema_generic_tests.py index 1200d2c6723..ccd9657f07e 100644 --- a/core/dbt/parser/schema_generic_tests.py +++ b/core/dbt/parser/schema_generic_tests.py @@ -134,7 +134,7 @@ def get_hashable_md(data: Union[str, int, float, List, Dict]) -> Union[str, List "column_name": column_name, "checksum": FileHash.empty().to_dict(omit_none=True), "file_key_name": file_key_name, - "meta": target.config.get('meta', {}) if hasattr(target, 'config') else {}, + "meta": target.config.get("meta", {}) if hasattr(target, "config") else {}, } try: GenericTestNode.validate(dct) From 5c767c39206c177d04a8c0971a4750966e9f6214 Mon Sep 17 00:00:00 2001 From: Tom Phillips Date: Thu, 3 Oct 2024 12:20:13 +0100 Subject: [PATCH 4/4] Fix failing test TestVerifyArtifactsVersions::test_versions --- tests/functional/artifacts/expected_manifest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/artifacts/expected_manifest.py b/tests/functional/artifacts/expected_manifest.py index 749a5b77619..b8786584b43 100644 --- a/tests/functional/artifacts/expected_manifest.py +++ b/tests/functional/artifacts/expected_manifest.py @@ -1760,7 +1760,7 @@ def expected_versions_manifest(project): "schema": test_audit_schema, "database": project.database, "tags": [], - "meta": {}, + "meta": {"size": "large", "color": "blue"}, "unique_id": "test.test.unique_versioned_model_v1_first_name.6138195dec", "docs": {"node_color": None, "show": True}, "compiled": True, @@ -1813,7 +1813,7 @@ def expected_versions_manifest(project): "schema": test_audit_schema, "database": project.database, "tags": [], - "meta": {}, + "meta": {"color": "blue", "size": "large"}, "unique_id": "test.test.unique_versioned_model_v1_count.0b4c0b688a", "docs": {"node_color": None, "show": True}, "compiled": True, @@ -1866,7 +1866,7 @@ def expected_versions_manifest(project): "schema": test_audit_schema, "database": project.database, "tags": [], - "meta": {}, + "meta": {"color": "blue", "size": "large"}, "unique_id": "test.test.unique_versioned_model_v2_first_name.998430d28e", "docs": {"node_color": None, "show": True}, "compiled": True,