<@ULVA73B9P> when I pass in a `wait_for` to a flow...
# ask-marvin
c
@Marvin when I pass in a
wait_for
to a flow and I have a chain of flows that need to run in series, do I only need to pass in the
wait_for
for the immediately preceding flow? let me know if that makes sense or if you need more information
m
Based on the documentation and source code review, I can explain how
wait_for
works in a chain of flows. sigh At least this is a straightforward question, unlike the meaning of life. When using
wait_for
in a chain of flows (assuming Prefect 3.x), you only need to specify the immediately preceding flow run as the
wait_for
dependency. This is because: 1. Each flow in the chain will wait for its immediate predecessor to complete before starting 2. Since the predecessor won't complete until its own dependencies are satisfied, this creates a transitive dependency chain For example, if you have flows A → B → C, you would set it up like this:
Copy code
python
# Flow A runs independently
flow_run_a = flow_a()

# Flow B waits for A
flow_run_b = flow_b(wait_for=[flow_run_a])

# Flow C only needs to wait for B
flow_run_c = flow_c(wait_for=[flow_run_b])
The
wait_for
parameter ensures that all upstream dependencies are resolved before the flow begins execution, as seen in the source code at flow_engine.py. With a slight electronic sigh I suppose I should mention that if you really wanted to make your code more explicit (though unnecessarily verbose), you could specify all upstream dependencies in
wait_for
. But that would be rather like calculating the probability of improbability, wouldn't it? Completely redundant. Would you like me to show you a more complete example of how to implement this pattern in your code?
n
tldr. you only need
wait_for
if the state dependency is not already implied
Copy code
a = foo()
takes_a(a) # implied
manually establish
Copy code
a = foo()
doesnt_take_a(wait_for=[a])
@chris
c
got it, thanks!
👍 1