How to access/transform task returned data before sending it to another task i.e. Thanks in advance!
Copy code
with prefect.Flow('myflow') as flow:
task_1 = my_task_1()
task_2 = my_task_2(task_1['value'])
z
Zanie
10/28/2021, 3:04 PM
Hey @Ahmed Ezzat - this will just work. We'll automatically generate a task to access the
"value"
key for you here.
Zanie
10/28/2021, 3:05 PM
You can't perform any transformations in the flow block and you need an intermediate task to do so. However, we will generate those intermediate tasks in some common cases .
a
Ahmed Ezzat
10/28/2021, 3:11 PM
Hi @Zanie Is there any workaround for applying transformations? i.e. not using a flow block or some other way?
z
Zanie
10/28/2021, 3:15 PM
Is there a reason you don't want to use tasks?
a
Ahmed Ezzat
10/28/2021, 3:23 PM
@Zanie It's just will result in a messy code. I'm ok with creating extra tasks however I want to access return values cleanly. My current Idea is to return a class then access its field. Is this implemented natively or I'll need to hack my way?
k
Kevin Kho
10/28/2021, 3:30 PM
I don’t think you can do this. The reason
task['value']
works is because Prefect uses a
GetItem
task under the hood when you call that. You will need to use a task for deferred execution. Accessing the class field will try to run during the build time, so no native way to immediate do it
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.