Hello everyone! What is the best way to access act...
# ask-community
s
Hello everyone! What is the best way to access actual mapped task results, I want to get only part of the result, E.g:
Copy code
intermediate_result = 0
with Flow("flow") as flow:
	param1 = Parameter("list1")
	mapped_list = create_map(param1)
	results = task1.map(mapped_list)
	intermediate_result = results[1]
	results2 = task2(results[1])
k
Hi @Satheesh K! Make a new helper task
Copy code
@task
def pull_first_element(results):
    return results[1]
Then use this new task as
intermediate_result = pull_first_element(results)
s
i actually did it, but it was returning the task instance, I was expecting actual result
k
You did it with a new task like above?
s
yes
tried both with and without task decorator
k
Can you try this script:
Copy code
import prefect
from prefect import Flow, task, unmapped

@task
def get_numbers():
    return [1,2,3]

@task
def first(x):
    return x[0]

@task
def my_log(first):
    logger = prefect.context.get("logger")
    <http://logger.info|logger.info>(f"Pulled the first value {first}")
    return first

with Flow('test-flow') as flow:
    n = get_numbers()
    first = first(n)
    my_log(first)

flow.run()
s
@Kevin Kho, thanks for the response, Here I am expecting 1 to be returned from
my_log
k
It is right?
Pulled the first value 1
s
okay, i think i am not asking my question properly. Here I want a way to assign
inter_res
with 1.
k
Ohhh!! I see the confusion
s
currently, it is a
Task
instance.
k
print
inside the Flow will not work because print is executed in build time but the values are populated in runtime.
You need to log inside the tasks instead
Everything inside the Flow should be tasks. Stuff like Parameters are then inserted during runtime. The
inter_res
will be assigned during build time but the value of
my_log(first)
will still just be a Task. You can’t get
inter_res
to be 1 inside a Flow
s
even during runtime?
k
During runtime it will get the value, but you won’t see it by printing it. You’ll see it if you just pass it to a task that logs.
I hope that clears things up?
s
I am confused, please give me some time to precisely articulate my question using an example
Thanks for your time and help
@Kevin Kho, While coming up with a better example, I realized a mistake in my flow. It is fixed now. Thank you very much for your response and help.
k
Happy to help and glad you figured it out 🙂