Hi, flyte team! I would like to ask `Promise obje...
# ask-the-community
s
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
@SeungTaeKim, you can unwrap promises in a Flyte task.
s
@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
Just pass the promise to a task
And it will be unwrapped
s
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
May I know why you want to access it in the workflow?
s
@Samhita Alla yeah! that's exactly what I wanted!
s
Okay, but why do you want to access it? I’d like to know your use-case.
k
@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.
158 Views