Hi, Is there a way to conditionally link steps. S...
# ask-metaflow
r
Hi, Is there a way to conditionally link steps. Say that I have some external condition that determines what downstream steps that should be executed. If the condition is fulfilled we run branch A and if it is not we run branch B. The workaround is to have branch A and B as separate flows that are triggered by the first steps, but Ideally I would like to do it in the same flow. Something like
Copy code
class MyFlow(FlowSpec):

@step
def first_step(self):
   condition = os.getenv(CONDITION)

   if condition:
      self.next(step_a1)
   else:
      self.next(step_b1)

@step
def step_a1(self):
   self.next(step_a2)

@step
def step_b1(self):
   self.next(step_b2)
When I have tried something similar I usually get an error saying that some steps can't be reached from the start step. Is there a way to ignore those steps if the condition isn't met?
1
a
we have active work in this direction that we are planning on releasing this week. if you want to test out the PR, here it is
🎉 1
r
Okay, cool! I'll check that out!
a
thanks! feedback would be highly appreciated 🙂 i am tagging @brainy-truck-72938 who owns this PR
👀 1
l
Ooh. This is fantastic news for me too! I can remove a little more jank from my code. Although, quick question: this would support conditions with more than two states, right? Essentially if elif else statements?
s
yep! available now
🎉 1