r

    Romain

    1 year ago
    Hello team, Is there a bug in "apply_map" working with flatten? I tried to modify the example from the doc (https://docs.prefect.io/core/concepts/mapping.html#flat-mapping) to use apply_map:
    from prefect import Flow, task, flatten, apply_map
    @task
    def A():
        return [1, 2, 3]
    
    @task
    def B(x):
        return list(range(x))
    
    @task
    def C(y):
        return y + 100
        
    def foo(y):
        return C(y)
    
    with Flow('flat map') as f:
        a = A() # [1, 2, 3]
        b = B.map(x=a) # [[0], [0, 1], [0, 1, 2]]
        c = apply_map(foo, y=flatten(b)) # [100, 100, 101, 100, 101, 102]
    While running it, I get : "TypeError: can only concatenate list (not "int") to list" Am I missing something?
    Zach Angell

    Zach Angell

    1 year ago
    Hi @Romain! Thanks for writing this up. This could be a bug, I'm digging a bit deeper into it. In the meantime, I'm happy to help with any workarounds if this is a blocker.
    r

    Romain

    1 year ago
    Hi @Zach Angell as a workaround I m using a FunctionTask to flatten my lists.
    Zach Angell

    Zach Angell

    1 year ago
    @Marvin open "apply_map does not flatten arguments correctly"