Skip to content

Commit 4ff334e

Browse files
committed
Use attribute name as authoritative step identifier in graph
FlowGraph._create_nodes walks dir(cls) by attribute name and stores nodes[element] = node, but DAGNode.name was derived from the AST def name. Those agreed only by convention. When a metaclass renames a function via __name__ (e.g. FunctionSpec synthesizing a step), AST parsing still reads the original def name, leaving nodes keyed by the attribute name while node.name reports the def name. FlowSpec._init_graph then does getattr(cls, node.name) and fails with AttributeError. Pass the discovered attribute name explicitly to DAGNode in the AST path, and have DAGNode prefer that over func_ast.name. Both paths (AST and the sourceless single-step fallback) now key on the same identifier. No behavior change for flows where def name and attribute name coincide, which is every ordinary flow.
1 parent 036ac35 commit 4ff334e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

metaflow/graph.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def __init__(
6565
if func_ast is None and name is None:
6666
raise ValueError("name is required when func_ast is None")
6767

68-
self.name = func_ast.name if func_ast is not None else name
68+
# Prefer explicit `name` (the attribute name under which the step was
69+
# discovered) over the AST-derived `def` name. This matters when a
70+
# metaclass renames a function via __name__ — the attribute name is
71+
# what getattr(cls, node.name) later looks up in FlowSpec._init_graph.
72+
self.name = name if name is not None else func_ast.name
6973
self.source_file = source_file
7074
# lineno is the start line of decorators in source_file
7175
# func_ast.lineno is lines from decorators start to def of function
@@ -397,6 +401,7 @@ def _create_nodes(self, flow):
397401
is_start_step=is_start,
398402
is_end_step=is_end,
399403
node_info=getattr(func, "node_info", None),
404+
name=element,
400405
)
401406
nodes[element] = node
402407
return nodes

0 commit comments

Comments
 (0)