Skip to content

Commit

Permalink
Drop metrics during upgrade_manifest_json if manifest is v9 or before
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Jun 8, 2023
1 parent 3bee5f5 commit 288cc76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
13 changes: 7 additions & 6 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
19 changes: 18 additions & 1 deletion core/dbt/contracts/graph/manifest_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 288cc76

Please sign in to comment.