Skip to content

Commit 24c9b4e

Browse files
authored
fix(vscode): protect from infinite loops (#4555)
1 parent 0872bac commit 24c9b4e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

web/server/api/endpoints/lineage.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def create_models_only_lineage_adjacency_list(
109109
"""Create an adjacency list representation of a column's lineage graph only with models"""
110110
graph: t.Dict[str, t.Dict[str, LineageColumn]] = defaultdict(dict)
111111
nodes = [(model_name, column_name)]
112+
# visited is a set of tuples of (model_name, column_name) to prevent infinite recursion
113+
visited = set()
114+
visited.add((model_name, column_name))
112115
while nodes:
113116
model_name, column = nodes.pop(0)
114117
model = context.get_model(model_name)
@@ -118,8 +121,10 @@ def create_models_only_lineage_adjacency_list(
118121
context, model_name, quote_column(column, model.dialect)
119122
).items():
120123
for column_name in column_names:
121-
dependencies[table].add(column_name)
122-
nodes.append((table, column_name))
124+
if (table, column_name) not in visited:
125+
dependencies[table].add(column_name)
126+
nodes.append((table, column_name))
127+
visited.add((table, column_name))
123128

124129
graph[model_name][column] = LineageColumn(models=dependencies)
125130
return graph

0 commit comments

Comments
 (0)