diff --git a/core/dbt/contracts/graph/manifest.py b/core/dbt/contracts/graph/manifest.py index 3ffd0e55fd7..0db18aae935 100644 --- a/core/dbt/contracts/graph/manifest.py +++ b/core/dbt/contracts/graph/manifest.py @@ -1020,6 +1020,57 @@ def build_group_map(self): group_map[node.group].append(node.unique_id) self.group_map = group_map + @classmethod + def from_writable_manifest(cls, writable_manifest: WritableManifest) -> "Manifest": + manifest = Manifest( + # TODO: update these as corresponding resources are created + nodes={node_id: node for node_id, node in writable_manifest.nodes.items()}, + disabled={ + disabled_node_id: disabled_node + for disabled_node_id, disabled_node in writable_manifest.disabled.items() + } + if writable_manifest.disabled is not None + else {}, + unit_tests={ + unit_test_id: unit_test + for unit_test_id, unit_test in writable_manifest.unit_tests.items() + }, + sources={ + source_id: SourceDefinition.from_resource(source) + for source_id, source in writable_manifest.sources.items() + }, + macros={ + macro_id: Macro.from_resource(macro) + for macro_id, macro in writable_manifest.macros.items() + }, + docs={ + doc_id: Documentation.from_resource(doc) + for doc_id, doc in writable_manifest.docs.items() + }, + exposures={ + exposure_id: Exposure.from_resource(exposure) + for exposure_id, exposure in writable_manifest.exposures.items() + }, + metrics={ + metric_id: Metric.from_resource(metric) + for metric_id, metric in writable_manifest.metrics.items() + }, + groups={ + group_id: Group.from_resource(group) + for group_id, group in writable_manifest.groups.items() + }, + selectors={ + selector_id: selector + for selector_id, selector in writable_manifest.selectors.items() + }, + semantic_models={ + semantic_model_id: SemanticModel.from_resource(semantic_model) + for semantic_model_id, semantic_model in writable_manifest.semantic_models.items() + }, + ) + + return manifest + def writable_manifest(self) -> "WritableManifest": self.build_parent_and_child_maps() self.build_group_map() diff --git a/core/dbt/contracts/state.py b/core/dbt/contracts/state.py index 9111e2dfb46..16683f8d899 100644 --- a/core/dbt/contracts/state.py +++ b/core/dbt/contracts/state.py @@ -1,7 +1,8 @@ from pathlib import Path from typing import Optional -from dbt.contracts.graph.manifest import WritableManifest +from dbt.contracts.graph.manifest import Manifest +from dbt.artifacts.schemas.manifest import WritableManifest from dbt.artifacts.schemas.freshness import FreshnessExecutionResultArtifact from dbt.artifacts.schemas.run import RunResultsArtifact from dbt_common.events.functions import fire_event @@ -24,7 +25,7 @@ def __init__(self, state_path: Path, target_path: Path, project_root: Path) -> N self.state_path: Path = state_path self.target_path: Path = target_path self.project_root: Path = project_root - self.manifest: Optional[WritableManifest] = None + self.manifest: Optional[Manifest] = None self.results: Optional[RunResultsArtifact] = None self.sources: Optional[FreshnessExecutionResultArtifact] = None self.sources_current: Optional[FreshnessExecutionResultArtifact] = None @@ -36,7 +37,8 @@ def __init__(self, state_path: Path, target_path: Path, project_root: Path) -> N manifest_path = self.project_root / self.state_path / "manifest.json" if manifest_path.exists() and manifest_path.is_file(): try: - self.manifest = WritableManifest.read_and_check_versions(str(manifest_path)) + writable_manifest = WritableManifest.read_and_check_versions(str(manifest_path)) + self.manifest = Manifest.from_writable_manifest(writable_manifest) except IncompatibleSchemaError as exc: exc.add_filename(str(manifest_path)) raise