question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subflow won't map over a `list` parameter

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
schmidt-jakecommented, Jan 3, 2020

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.

0reactions
lauralorenzcommented, Apr 9, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found