https://prefect.io logo
#prefect-community
Title
# prefect-community
d

Derek Heyman

06/08/2022, 8:10 PM
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?
Copy code
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
k

Kevin Kho

06/08/2022, 8:17 PM
Do you have sample code I can look at?
d

Derek Heyman

06/08/2022, 8:20 PM
Just sent in a DM
k

Kevin Kho

06/09/2022, 12:20 AM
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?
d

Derek Heyman

06/09/2022, 2:49 AM
Hi @Kevin Kho, I previously tried removing that and received the same error
k

Kevin Kho

06/09/2022, 5:10 AM
I guess the next question if is if the mapped tasks all have the same length?
d

Derek Heyman

06/09/2022, 2:06 PM
What do you mean by this?
k

Kevin Kho

06/09/2022, 2:21 PM
If you do:
Copy code
A.map(input1, input2)
B.map(A, other_input)
C.map(B, other_input2)
Are all of the inputs the same length?
d

Derek Heyman

06/09/2022, 9:35 PM
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
k

Kevin Kho

06/09/2022, 9:36 PM
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?
d

Derek Heyman

06/10/2022, 2:42 AM
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
👍 1
k

Kevin Kho

06/10/2022, 2:50 AM
Nice! Glad you sorted it out
7 Views