Hi all! I have this workflow where I need to check...
# flyte-support
i
Hi all! I have this workflow where I need to check gcs for a file, if exists: do a subworkflow, otherwise just do nothing and succeed the wf. I have a task called noop that does nothing. However: when I register this, i get this error:
Copy code
failed to compile workflow for [resource_type:WORKFLOW project:"projectneame" domain:"development" name:"flyte.workflows.wf.wf" version:"test"] with err failed to compile workflow with err Collected Errors: 1
        Error 0: Code: ValueRequired, Node Id: n1, Description: Value required [RightValue.Val].
my code looks something like this
Copy code
csv_file = get_file(dir: FlyteDirectory ...) -> Optional[FlyteFile]

    resulsts = (
        conditional("con")
        .if_(csv_file == None) # or if_(csv_file.is_none())
        .then(noop())
        .else_()
        .then(subwf(csv_file))
    )
what does is_none mean? cant it handle Optional inputs? how to solve this issue here without introducing another task that returns a boolean ?
t
https://discuss.flyte.org/t/13223035/hi-community-i-just-encounter-such-error-when-i-tried-to-imp#9b60534d-bb77-4bce-8683-992f6ffecf90 seems like
is_none
doesn't work on promises and the output types of the
then
nodes must be the same.
i
But the == None didn’t work as well
So after trying, it seems that only booleans work normally. if a task returns a dataclass or a namedtuple, using a filed in the condition wont work. the only solution is to unpack the output of a task and use the boolean directly with
is_true()
and
is_false()
t
what do you mean only booleans work normally?
i
Is none doesnt work
== , > , < …etc dont work with other tasks output
t
namedtuples are fundamentally different than dataclasses btw. namedtuples are the way outputs are named, and represent multiple outputs. dataclasses represent one output.
i
Namedtuples are another case
t
i see
what’s the error you’re getting?
only primitives can be evaluated for things like >, <, ==… you’re right. but is none should work.
i am getting a
ValueError: Only primitive values can be used in comparison
is that the same error you’re seeing?
i
== None doesnt work right. Same error But when i use is_none on a promise: ie output of a previous task i get Value required error
Like i mentioned above
t
this is my test case…
Copy code
def test_condition_is_none2():
    @dataclass
    class MyDataClass(DataClassJSONMixin):
        a: int
        b: str

    @task
    def maybe_str(a: int) -> typing.Optional[MyDataClass]:
        if a > 5:
            return MyDataClass(a=a, b="hello")
        return None

    @task
    def failed() -> int:
        return 10

    @task
    def success() -> int:
        return 20

    @workflow
    def decompose_unary() -> int:
        result = maybe_str(a=6)
        return conditional("test").if_(result.is_none()).then(success()).else_().then(failed())

    xx = decompose_unary()
    print(xx)
a
@thankful-minister-83577 or @important-hamburger-34837 was there a work around here?
i
I defined a task that returns a tuple, the actual file and a boolean, then used the boolean to complete the condition
a
Thanks that worked for me too.
👍 1
i
Copy code
def task() -> Tuple[Optional[FlyteFile], bool]:
    f = get_file()
    exists = f is not None # or whatever
    return f, exists

@workflow
def wf():
        csv_file, exists = task(dir: FlyteDirectory ...)

    resulsts = (
        conditional("con")
        .if_(exists.is_false())
        .then(noop())
        .else_()
        .then(subwf(do sometrhing...))
    )