https://flyte.org logo
#ask-the-community
Title
# ask-the-community
s

SeungTaeKim

10/31/2022, 4:25 AM
Hi, flyte team! I would like to ask
Promise object
of task's return values.
Copy code
from flytekit import workflow, task, dynamic, conditional
from flytekit.core.promise import Promise

@task
def t1() -> bool:
    return True


@task
def t2() -> bool:
    return False


@workflow
def wf() -> bool:
    test = t1()
    print(test)
    return t2()


if __name__ == "__main__":
    print(wf())
when I run this sample codes through
pyflyte
, a task returns
Promise object
, and literal or objects I expect are wrapped in
Promise
. So, here is my question, how I unwrap this promise object? I would like to use the expected value from the function. Thank you!
s

Samhita Alla

10/31/2022, 4:28 AM
@SeungTaeKim, you can unwrap promises in a Flyte task.
s

SeungTaeKim

10/31/2022, 4:29 AM
@Samhita Alla would you explain it in detail? I got a result below
Copy code
Promise(node:n0.o0)
Resolved(o0=scalar {
  primitive {
    boolean: true
  }
}
)
k

Ketan (kumare3)

10/31/2022, 4:35 AM
Just pass the promise to a task
And it will be unwrapped
s

SeungTaeKim

10/31/2022, 4:54 AM
I am looking for other solution, not to pass Promise object to the other tasks, but unwrap it in workflow itself. official docs link I have already knew @Ketan (kumare3) mentioned below
Copy code
from flytekit import workflow, task, dynamic, conditional
from flytekit.core.promise import Promise

@task
def t1() -> bool:
    validation(return_value)
    return True


@task
def t2(a:bool) -> bool:
    print(a)
    return False


@workflow
def wf() -> bool:
    test = t1()
    # print(test)
    return t2(a=test)


if __name__ == "__main__":
    print(wf())
s

Samhita Alla

10/31/2022, 5:05 AM
May I know why you want to access it in the workflow?
s

SeungTaeKim

10/31/2022, 5:05 AM
@Samhita Alla yeah! that's exactly what I wanted!
s

Samhita Alla

10/31/2022, 5:07 AM
Okay, but why do you want to access it? I’d like to know your use-case.
k

Ketan (kumare3)

10/31/2022, 5:10 AM
@SeungTaeKim - Promise objects are “promises” that means they promise that data will be available at runtime. At static time, when workflows are create these are not available and cannot be unwrapped. Workflow code does not run when a workflow is being executed. so there is no way to add code in the workflow to inspect the promise. Only way to do that is to use
@dynamic
, but it is still limited to the inputs to a dynamic task.
70 Views