From fb1bbdcbc1a2112ed4cf10956b18b7007897f0d7 Mon Sep 17 00:00:00 2001 From: "Ching Yi, Chan" Date: Mon, 4 Sep 2023 15:32:28 +0800 Subject: [PATCH] [Bug] Fix upgrade_schema bug to keep metrics data (#871) * Fix upgrade_schema bug to keep metrics data Signed-off-by: Ching Yi, Chan Co-authored-by: wcchang Co-authored-by: popcorny * Update no-profiled criteria Signed-off-by: Ching Yi, Chan --------- Signed-off-by: Ching Yi, Chan Co-authored-by: wcchang Co-authored-by: popcorny --- piperider_cli/dbt/list_task.py | 19 ++++++++++++++++++- piperider_cli/runner.py | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/piperider_cli/dbt/list_task.py b/piperider_cli/dbt/list_task.py index c0a2a772b..b2069279c 100644 --- a/piperider_cli/dbt/list_task.py +++ b/piperider_cli/dbt/list_task.py @@ -1,5 +1,6 @@ import argparse import json +import re import tempfile from dataclasses import fields from pathlib import Path @@ -103,7 +104,23 @@ def _load_manifest_version_15(manifest: Dict): ] raise ValueError(messages) - return WritableManifest.upgrade_schema_version(data) + def patched_get_manifest_schema_version(dct: dict) -> int: + schema_version = dct.get("metadata", {}).get("dbt_schema_version", None) + if not schema_version: + raise ValueError("Manifest doesn't have schema version") + + match = re.search(r'/v(\d+).json', schema_version) + if match: + return int(match.group(1)) + raise ValueError("Manifest doesn't have schema version") + + import dbt.contracts.graph.manifest + origin_function = dbt.contracts.graph.manifest.get_manifest_schema_version + dbt.contracts.graph.manifest.get_manifest_schema_version = patched_get_manifest_schema_version + + result = WritableManifest.upgrade_schema_version(data) + dbt.contracts.graph.manifest.get_manifest_schema_version = origin_function + return result def _load_manifest_version_16(manifest: Dict): diff --git a/piperider_cli/runner.py b/piperider_cli/runner.py index 6007c1b80..8c35b44fb 100644 --- a/piperider_cli/runner.py +++ b/piperider_cli/runner.py @@ -908,7 +908,7 @@ def _slim_dbt_manifest(manifest): if not _check_assertion_status(assertion_results, assertion_exceptions): return EC_ERR_TEST_FAILED - if len(subjects) == 0: + if len(subjects) == 0 and len(run_result.get('metrics', [])) == 0: return EC_WARN_NO_PROFILED_MODULES return 0