From 38cdbb77e0127ca5a8cf4bb10f78533dfb75e9f9 Mon Sep 17 00:00:00 2001 From: popcorny Date: Wed, 12 Jun 2024 16:33:29 +0800 Subject: [PATCH] The recce summary would raise exception if node is excluded from the lineage object Signed-off-by: popcorny --- recce/adapter/dbt_adapter/__init__.py | 4 ++-- recce/summary.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/recce/adapter/dbt_adapter/__init__.py b/recce/adapter/dbt_adapter/__init__.py index d975e701..3278a304 100644 --- a/recce/adapter/dbt_adapter/__init__.py +++ b/recce/adapter/dbt_adapter/__init__.py @@ -392,8 +392,6 @@ def get_lineage(self, base: Optional[bool] = False): manifest_dict = manifest.to_dict() - parent_map = {k: v for k, v in manifest_dict['parent_map'].items() if not k.startswith('test.')} - nodes = {} for node in manifest_dict['nodes'].values(): @@ -492,6 +490,8 @@ def get_lineage(self, base: Optional[bool] = False): 'config': semantic_models['config'], } + nodeIds = nodes.keys() + parent_map = {k: v for k, v in manifest_dict['parent_map'].items() if k in nodeIds} return dict( parent_map=parent_map, nodes=nodes, diff --git a/recce/summary.py b/recce/summary.py index fb17dc8a..d92fcde8 100644 --- a/recce/summary.py +++ b/recce/summary.py @@ -1,3 +1,4 @@ +import sys from typing import List, Dict, Set, Union, Type, Optional from uuid import UUID @@ -18,6 +19,11 @@ REMOVE_COLOR = '#ff067e' +def _warn(msg): + # print to stderr + print(f"warning: {msg}", file=sys.stderr) + + class Node: id: str name: str @@ -219,9 +225,11 @@ def create_node(self, node_id: str, node_data: dict, data_from: str = 'base'): def create_edge(self, parent_id: str, child_id: str, edge_from: str = 'base'): if parent_id not in self.nodes: - raise ValueError(f'Parent node {parent_id} not found in graph') + _warn(f'Parent node {parent_id} not found in graph') + return if child_id not in self.nodes: - raise ValueError(f'Child node {child_id} not found in graph') + _warn(f'Child node {child_id} not found in graph') + return edge_id = f'{parent_id}-->{child_id}' if edge_id in self.edges: