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

Hank Huang

07/18/2023, 2:38 AM
Hi community, I have some problem when implement the new function in Promise. I want to add is_None to check if the value of Promise is None, no matter how I pass the input, as long as I call this function. It will show ups this exception (attachment), However, I have no clue to this. Here is my new function I’ve tried
Copy code
def is_None(self):
        return ComparisonExpression(self, ComparisonOps.EQ, None)

    def is_None(self):
        return self == None
Here is my tested workflow
Copy code
@task(limits=Resources(mem="1Gi",cpu="1"))
def none_func()->str:
    return f"the input is None"

@task(limits=Resources(mem="1Gi",cpu="1"))
def not_none_func(obj)->str:
    return f"the input {obj} is not None"

@task(limits=Resources(mem="1Gi",cpu="1"))
def get_none() -> None:
    return None

@task(limits=Resources(mem="1Gi",cpu="1"))
def get_int() -> int:
    return 100

@workflow
def none_wf2()->str:
    my_input = get_int()

    return (
        conditional("testing_none")
        .if_(my_input.is_None())
        .then(none_func())
        .else_()
        .then(not_none_func(obj=my_input))
    )
Thanks for the response!
j

Jay Ganbat

07/18/2023, 3:11 AM
hm i think it might be this
is_(None)
here is the source code
Copy code
def is_(self, v: bool) -> ComparisonExpression:
        return ComparisonExpression(self, ComparisonOps.EQ, v)

    def is_false(self) -> ComparisonExpression:
        return self.is_(False)

    def is_true(self):
        return self.is_(True)
h

Hank Huang

07/18/2023, 3:14 AM
Hi @Jay Ganbat, Thanks for the response! I am curious the reason behind this thought, can you share a bit more?
btw, I just tired the method you provide! thanks again. Unfortunately, it still shows the same error
j

Jay Ganbat

07/18/2023, 3:21 AM
can you try
Optional[int]
in your get_int method since it returns Int so im not sure it can be none according to type
oh i took the method signature from
Promise
object, the way its called before is you are calling a custom method so i dont think it can be called on Promise object
h

Hank Huang

07/18/2023, 3:29 AM
Hi @Jay Ganbat, Thanks for the response! Here is my updated workflow, but it still shows up the same exception.
image.png
j

Jay Ganbat

07/18/2023, 3:29 AM
can you try this
is_(None)
you are still calling
is_None()
method 🤔
so it should be called
my_input.is_(None)
since
my_input
will be Promise type during registration
h

Hank Huang

07/18/2023, 3:32 AM
yes, you’re correct. After the test result based on the following, it still shows the same exception
Copy code
@workflow
def none_wf2()->str:
    my_input = get_others()
    method_source = inspect.getsource(my_input.is_None)
    print(method_source)

    return (
        conditional("testing_none")
        .if_(my_input.is_(None))
        .then(none_func())
        .else_()
        .then(not_none_func(obj=my_input))
    )
j

Jay Ganbat

07/18/2023, 3:33 AM
can you comment out the inspect part
h

Hank Huang

07/18/2023, 3:34 AM
ok
Here is the result. looks like the same
j

Jay Ganbat

07/18/2023, 3:42 AM
is your
get_others
same as
get_int
h

Hank Huang

07/18/2023, 3:44 AM
My bad, they are different, but similar. However, I change it to get_int, it still the same
j

Jay Ganbat

07/18/2023, 3:45 AM
ohhh i know why i think its your
none_func()
its returning
None
but your workflow outputs
str
so make the output of your worklfow Optional[str]
h

Hank Huang

07/18/2023, 3:48 AM
I see, Thanks for the advice. However, even I change the return type with Optional[str], the error remain the same. Here are the whole implementation of the workflow.
Copy code
@task(limits=Resources(mem="1Gi",cpu="1"))
def none_func()->Optional[str]:
    return f"the input is None"

@task(limits=Resources(mem="1Gi",cpu="1"))
def not_none_func(obj)->Optional[str]:
    return f"the input {obj} is not None"

@task(limits=Resources(mem="1Gi",cpu="1"))
def get_none() -> None:
    return None

@task(limits=Resources(mem="1Gi",cpu="1"))
def get_int() -> Optional[int]:
    return 100

@workflow
def none_wf2()->str:
    my_input = get_int()

    return (
        conditional("testing_none")
        .if_(my_input.is_(True))
        .then(none_func())
        .else_()
        .then(not_none_func(obj=my_input))
    )
I think the problem is where I call
my_input.is_(None)
=> that the part cause the error.
j

Jay Ganbat

07/18/2023, 3:51 AM
hmm its the
none_wf2() -> Optional[str]
but i actually never tried to explicitly check for None i usually just return
get_int()
or any conditional check to return bool and use is_true() on it
h

Hank Huang

07/18/2023, 4:02 AM
Hi @Jay Ganbat Sorry I don’t understand your point, can you be more specific?
j

Jay Ganbat

07/18/2023, 4:05 AM
we have 1 conditioanl workflow in our repo and it has the following structure
Copy code
def is_none(myinput) -> bool:
    return some_conditional_method(myinput)

def my_wf()...
    result = is_none(in_spec_path=in_spec_path)
    out_aligned_bam_gs, out_metrics = (
        conditional("MYWF")
        .if_(result.is_true())
        .then(
            call_first_task()
        )
        .else_()
        .then(
            call_the_other_task()
        )
    )
h

Hank Huang

07/18/2023, 4:16 AM
I see. Thanks for sharing.
Here is the related issue. https://github.com/flyteorg/flyte/issues/3514 That’s why I want to implement a function to test if it’s a none
@Jay Ganbat Thanks for the advice again!
j

Jay Ganbat

07/18/2023, 4:35 AM
ohh i see 😬 thats why it wasnt working 😅
h

Hank Huang

07/18/2023, 4:40 AM
But I think I need to do more than just ass Is_None
20 Views