alexandrusoare commented on code in PR #44892:
URL: https://github.com/apache/superset/pull/44892#discussion_r4183750454


##########
superset/commands/deletion_retention/purge_policy.py:
##########
@@ -329,34 +363,34 @@ def _discover_table_dependencies(
             if constraint.elements[0].column.table is table:
                 discovered.add(_fk_key(table, constraint, "inbound"))
     discovered.update(
-        _discover_recursive_table_dependencies(
-            table,
-            recursive_tables=recursive_tables,
-            visited=next_visited,
-        )
+        _discover_recursive_table_dependencies(table, recursive_tables, seen)
     )
     return frozenset(discovered)
 
 
 def _discover_recursive_table_dependencies(
     table: sa.Table,
-    *,
     recursive_tables: frozenset[str],
-    visited: frozenset[str],
+    seen: _Traversal,
 ) -> frozenset[DependencyKey]:
-    """Discover dependencies for named recursive tables not already visited."""
+    """Discover dependencies for named recursive tables not already visited.
+
+    Sorted so a traversal is reproducible, and driven off the shared
+    bookkeeping so each table is walked at most once per kind of walk.
+    """
     discovered: set[DependencyKey] = set()
-    for recursive_table_name in recursive_tables - visited:
+    for recursive_table_name in sorted(recursive_tables - seen.tables):
+        # Re-checked inside the loop: the set grows as the walk descends, so
+        # a table a nested call already covered is skipped rather than
+        # re-entered to return nothing.
+        if recursive_table_name in seen.tables:

Review Comment:
   Added tests



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to