Skip to content

Commit

Permalink
Backport #10103 to 1.8.latest (#10106)
Browse files Browse the repository at this point in the history
* Backport #10103 to 1.8.latest

* Add changie
  • Loading branch information
jtcohen6 authored May 8, 2024
1 parent bbfd03e commit 8926c2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240508-132133.yaml
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 7 additions & 5 deletions core/dbt/artifacts/schemas/run/v5/run.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/artifacts/test_run_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8926c2c

Please sign in to comment.