Subflow won't map over a `list` parameter
See original GitHub issueDescription
A clear description of the bug
I have a flow that maps a task to a list. Each list item itself is a list. The task runs a subflow that has a task mapped to each element of that nested list that runs conditionally. This prevents me from simply flattening the nested list and doing a single map. The subflow receives each nested list as a pf.Parameter
. The apparent bug is that inside this subflow, the Task
mapped to the inner list receives the entire inner list instead of just an element, and the Task
is called len(list)
times with this argument.
Expected Behavior
What did you expect to happen instead? I expected my inner map to receive a single element of the nested list.
Reproduction
A minimal example that exhibits the behavior.
import prefect as pf
@pf.task
def process_list_element(element):
print('ELEMENT:', element)
@pf.task
def run_map_flow(inner_list, nested_flow):
print('LIST:', inner_list)
if is_valid(inner_list):
nested_flow.run(inner_list=inner_list)
@pf.task
def make_nested_list(i):
nested_list = [list(range(i)) for _ in range(i)]
print('NESTED LIST: ', nested_list)
return nested_list
if __name__ == '__main__':
with pf.Flow('nested_flow') as nested_flow:
inner_list = pf.Parameter('inner_list')
process_list_element.map(inner_list)
with pf.Flow('outer_flow') as outer_flow:
nested_list = make_nested_list(3)
run_map_flow.map(nested_list, nested_flow=pf.unmapped(nested_flow))
nested_flow.run(inner_list=range(10)) # runs as expected
outer_flow.run() # not what I expected
Environment
python 3.6.8 prefect 0.8.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Spring webflow Value of second parameter is not passed ...
Now I am able to see value of 'value2' but value for 'value1' receiving is null. What is wrong here? see below debug...
Read more >Parent-flows' parameter value doesn't passed to sub-flow
Parameters (i.e. param.HarnessPurpose) of parent-flow was filled with a specified value (i.e. Perform); and this parameter value will be passed ...
Read more >How to set a list as parameter values in DeploymentSpec ...
I am trying to map each item of the parameter list to process_forecast: e.g. for stid in STATION_IDS: process_forecast(stid). But right now it's...
Read more >Subflows
Define a sequence of reusable actions that can be started from a flow, subflow, or script. Define inputs and outputs to pass data...
Read more >Use Subflow Elements with Evaluation Flows
Get More Reliable Initial Datasets in the Event Monitoring Analytics... Verify Your Email Address to Send Email Through Salesforce · Make Calls from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Understood! Unfortunately, flattening won’t work in my case because there is some conditional logic that determines the execution of the nested list. I’ll update my code example to reflect what I mean.
Closing, there was some offline chatter about this that we think means this issue is resolved, and on top of that, upcoming subflows feature may help make this paradigm a more first class experience.