Skip to content

Commit b8507e3

Browse files
committed
feedback
1 parent 93ce1e2 commit b8507e3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

sqlmesh/utils/dag.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ def _find_cycle_path(self, nodes_in_cycle: t.Dict[T, t.Set[T]]) -> t.Optional[t.
113113

114114
# Use DFS to find a cycle path
115115
visited: t.Set[T] = set()
116-
rec_stack: t.Set[T] = set()
117116
path: t.List[T] = []
118117

119118
def dfs(node: T) -> t.Optional[t.List[T]]:
120-
if node in rec_stack:
119+
if node in path:
121120
# Found a cycle - extract the cycle path
122121
cycle_start = path.index(node)
123122
return path[cycle_start:] + [node]
@@ -126,7 +125,6 @@ def dfs(node: T) -> t.Optional[t.List[T]]:
126125
return None
127126

128127
visited.add(node)
129-
rec_stack.add(node)
130128
path.append(node)
131129

132130
# Only follow edges to nodes that are still in the unprocessed set
@@ -136,7 +134,6 @@ def dfs(node: T) -> t.Optional[t.List[T]]:
136134
if cycle:
137135
return cycle
138136

139-
rec_stack.remove(node)
140137
path.pop()
141138
return None
142139

@@ -180,7 +177,10 @@ def sorted(self) -> t.List[T]:
180177

181178
last_processed_msg = ""
182179
if cycle_path:
183-
cycle_msg = f"\nCycle: {' -> '.join(str(node) for node in cycle_path)} -> {cycle_path[0]}"
180+
node_output = " ->\n".join(
181+
str(node) for node in (cycle_path + [cycle_path[0]])
182+
)
183+
cycle_msg = f"\nCycle:\n{node_output}"
184184
else:
185185
# Fallback message in case a cycle can't be found
186186
cycle_candidates_msg = (

tests/utils/test_dag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_sorted_with_cycles():
5757

5858
expected_error_message = (
5959
"Detected a cycle in the DAG. Please make sure there are no circular references between nodes.\n"
60-
"Cycle: d -> e -> d"
60+
"Cycle:\nd ->\ne ->\nd"
6161
)
6262

6363
assert expected_error_message == str(ex.value)
@@ -69,7 +69,7 @@ def test_sorted_with_cycles():
6969

7070
expected_error_message = (
7171
"Detected a cycle in the DAG. Please make sure there are no circular references between nodes.\n"
72-
"Cycle: a -> b -> c -> a"
72+
"Cycle:\na ->\nb ->\nc ->\na"
7373
)
7474

7575
assert expected_error_message == str(ex.value)
@@ -81,7 +81,7 @@ def test_sorted_with_cycles():
8181

8282
expected_error_message = (
8383
"Detected a cycle in the DAG. Please make sure there are no circular references between nodes.\n"
84-
+ "Cycle: b -> d -> b"
84+
+ "Cycle:\nb ->\nd ->\nb"
8585
)
8686

8787
assert expected_error_message == str(ex.value)

0 commit comments

Comments
 (0)