diff --git a/core/dbt/contracts/graph/manifest.py b/core/dbt/contracts/graph/manifest.py index 21d11cf3acd..0ce4cb110a8 100644 --- a/core/dbt/contracts/graph/manifest.py +++ b/core/dbt/contracts/graph/manifest.py @@ -972,11 +972,11 @@ def pydantic_semantic_manifest(self) -> Optional[PydanticSemanticManifest]: pydantic_semantic_manifest = PydanticSemanticManifest(metrics=[], semantic_models=[]) # TODO uncommet after getting changes from https://github.com/dbt-labs/dbt-core/pull/7769 - # for semantic_model in manifest.semantic_models: - # pydantic_semantic_manifest.metrics.append(PydanticSemanticManifest.parse_obj(semantic_model)) + # for semantic_model in manifest.semantic_models.values(): + # pydantic_semantic_manifest.metrics.append(PydanticSemanticManifest.parse_obj(semantic_model.to_dict())) - for metric in self.metrics: - pydantic_semantic_manifest.metrics.append(PydanticMetric.parse_obj(metric)) + for metric in self.metrics.values(): + pydantic_semantic_manifest.metrics.append(PydanticMetric.parse_obj(metric.to_dict())) return pydantic_semantic_manifest @@ -1347,8 +1347,9 @@ def compatible_previous_versions(self): def upgrade_schema_version(cls, data): """This overrides the "upgrade_schema_version" call in VersionedSchema (via ArtifactMixin) to modify the dictionary passed in from earlier versions of the manifest.""" - if get_manifest_schema_version(data) <= 9: - data = upgrade_manifest_json(data) + manifest_schema_version = get_manifest_schema_version(data) + if manifest_schema_version <= 9: + data = upgrade_manifest_json(data, manifest_schema_version) return cls.from_dict(data) def __post_serialize__(self, dct): diff --git a/core/dbt/contracts/graph/manifest_upgrade.py b/core/dbt/contracts/graph/manifest_upgrade.py index c49d395133e..8e46c893fc1 100644 --- a/core/dbt/contracts/graph/manifest_upgrade.py +++ b/core/dbt/contracts/graph/manifest_upgrade.py @@ -49,7 +49,24 @@ def upgrade_seed_content(node_content): node_content.get("depends_on", {}).pop("nodes", None) -def upgrade_manifest_json(manifest: dict) -> dict: +def drop_v9_and_prior_metrics(manifest: dict) -> None: + manifest["metrics"] = {} + filtered_disabled_entries = {} + for entry_name, resource_list in manifest.get("disabled", {}).items(): + filtered_resource_list = [] + for resource in resource_list: + if resource.get("resource_type") != "metric": + filtered_resource_list.append(resource) + filtered_disabled_entries[entry_name] = filtered_resource_list + + manifest["disabled"] = filtered_disabled_entries + + +def upgrade_manifest_json(manifest: dict, manifest_schema_version: int) -> dict: + # this should remain 9 while the check in `upgrade_schema_version` may change + if manifest_schema_version <= 9: + drop_v9_and_prior_metrics(manifest=manifest) + for node_content in manifest.get("nodes", {}).values(): upgrade_node_content(node_content) if node_content["resource_type"] == "seed":