diff --git a/.changes/unreleased/Fixes-20240508-132133.yaml b/.changes/unreleased/Fixes-20240508-132133.yaml new file mode 100644 index 00000000000..b0c5935def3 --- /dev/null +++ b/.changes/unreleased/Fixes-20240508-132133.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Undo conditional agate import to prevent UnresolvedTypeReferenceError during + RunResult serialization +time: 2024-05-08T13:21:33.604231+02:00 +custom: + Author: jtcohen6 + Issue: "10098" diff --git a/core/dbt/artifacts/schemas/run/v5/run.py b/core/dbt/artifacts/schemas/run/v5/run.py index d3e6bfa4ece..c886cce7dd1 100644 --- a/core/dbt/artifacts/schemas/run/v5/run.py +++ b/core/dbt/artifacts/schemas/run/v5/run.py @@ -1,9 +1,15 @@ import threading -from typing import Any, Optional, Iterable, Tuple, Sequence, Dict, TYPE_CHECKING +from typing import Any, Optional, Iterable, Tuple, Sequence, Dict import copy from dataclasses import dataclass, field from datetime import datetime +# https://github.com/dbt-labs/dbt-core/issues/10098 +# Needed for Mashumaro serialization of RunResult below +# TODO: investigate alternative approaches to restore conditional import +# if TYPE_CHECKING: +import agate + from dbt_common.constants import SECRET_ENV_PREFIX from dbt.artifacts.resources import CompiledResource @@ -24,10 +30,6 @@ from dbt.exceptions import scrub_secrets -if TYPE_CHECKING: - import agate - - @dataclass class RunResult(NodeResult): agate_table: Optional["agate.Table"] = field( diff --git a/tests/functional/artifacts/test_run_results.py b/tests/functional/artifacts/test_run_results.py index 7f136afdb60..537db015198 100644 --- a/tests/functional/artifacts/test_run_results.py +++ b/tests/functional/artifacts/test_run_results.py @@ -40,6 +40,22 @@ def test_timing_exists(self, project): assert len(results.results[0].timing) > 0 +class TestRunResultsSerializableInContext: + @pytest.fixture(scope="class") + def models(self): + return {"model.sql": good_model_sql} + + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "on-run-end": ["{% for result in results %}{{ log(result.to_dict()) }}{% endfor %}"] + } + + def test_results_serializable(self, project): + results = run_dbt(["run"]) + assert len(results.results) == 1 + + # This test is failing due to the faulty assumptions that run_results.json would # be written multiple times. Temporarily disabling. @pytest.mark.skip()