Hey Team ! I am running a argo-workflow using met...
# ask-metaflow
a
Hey Team ! I am running a argo-workflow using metaflow. for my use case i need access to the parent node name of a join node. Is there a way to get it ? i could not find it in the API docs.
c
Hello! Option 1: Using client + manual approach
Copy code
from metaflow import FlowSpec, step, current

class ParentLookupFlow(FlowSpec):
    @step
    def start(self):
        self.next(self.a, self.b)

    @step
    def a(self):
        self.step_name = current.step_name
        self.next(self.join)
    
    @step
    def b(self):
        self.step_name = current.step_name
        self.next(self.join)

    @step
    def join(self, inputs):
        parents = [inp.step_name for inp in inputs]
        print("My parents are:", parents)
        self.next(self.end)

    @step
    def end(self):
        pass

if __name__ == "__main__":
    ParentLookupFlow()
Option 2: Messier Metaflow internals approach without polluting upstream steps
Copy code
from metaflow import FlowSpec, step

class ParentLookupFlow(FlowSpec):
    @step
    def start(self):
        self.next(self.a, self.b)

    @step
    def a(self):
        self.next(self.join)
    
    @step
    def b(self):
        self.next(self.join)

    @step
    def join(self, inputs):
        my_name = self._current_step
        parents = []
        for k,v in self._graph_info['steps'].items():
            if my_name in v['next']:
               parents.append(v['name'])
        print("My parents are:", parents)
        self.next(self.end)

    @step
    def end(self):
        pass

if __name__ == "__main__":
    ParentLookupFlow()