Derek Heyman

    Derek Heyman

    3 months ago
    I'm attempting to use map to reuse tasks and am running into the following error. Any insight into what I might be doing wrong?
    Unexpected error: KeyError(0)
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/prefect/engine/runner.py", line 48, in inner
        new_state = method(self, state, *args, **kwargs)
      File "/usr/local/lib/python3.8/site-packages/prefect/engine/flow_runner.py", line 569, in get_flow_run_state
        executors.prepare_upstream_states_for_mapping(
      File "/usr/local/lib/python3.8/site-packages/prefect/utilities/executors.py", line 681, in prepare_upstream_states_for_mapping
        value = upstream_state.result[i]
    KeyError: 0
    Kevin Kho

    Kevin Kho

    3 months ago
    Do you have sample code I can look at?
    Derek Heyman

    Derek Heyman

    3 months ago
    Just sent in a DM
    Kevin Kho

    Kevin Kho

    3 months ago
    I went through the Flow and the only obvious thing is the
    if
    in the Flow block will likely not work
    You have to use the case task I think?
    Derek Heyman

    Derek Heyman

    3 months ago
    Hi @Kevin Kho, I previously tried removing that and received the same error
    Kevin Kho

    Kevin Kho

    3 months ago
    I guess the next question if is if the mapped tasks all have the same length?
    Derek Heyman

    Derek Heyman

    3 months ago
    What do you mean by this?
    Kevin Kho

    Kevin Kho

    3 months ago
    If you do:
    A.map(input1, input2)
    B.map(A, other_input)
    C.map(B, other_input2)
    Are all of the inputs the same length?
    Derek Heyman

    Derek Heyman

    3 months ago
    I'm not sure what you mean by this. The different tasks that I am calling require different inputs. One of those inputs for each of those mapped tasks is sources, but each task requires a different set of inputs
    Kevin Kho

    Kevin Kho

    3 months ago
    Yes if
    other_input2
    is a list with 2 items and B is a list of 3 items for
    C
    , you can run into problems. Does that make sense?
    Derek Heyman

    Derek Heyman

    3 months ago
    Posting here for reference: Kevin helped me to figure out that I was passing unmapped variables to my mapped task. If you intend to map a task, all arguments must be mapped. If you have a variable that is not mapped, use the unmapped function so that your variable (in my case a string), doesn't get interpretted as a map of size string length. Thanks @Kevin Kho https://docs.prefect.io/core/concepts/mapping.html#unmapped-inputs
    Kevin Kho

    Kevin Kho

    3 months ago
    Nice! Glad you sorted it out