Does anyone have a cleaner way of doing things in ...
# ask-the-community
j
Does anyone have a cleaner way of doing things in the following scenario •
task_with_optional_return
returns optional FlyteFile •
dynamic_task
that calls above task BUT returns regular FlyteFile How do i cleanly resolve this optional types. For now i had to create a temporary task that takes in
Optional[FlyteFile]
and return
Flytefile
but creating an entire new task just for this type conversion is just a bit ugly 😅 unfortunately i cannot check for `None`because during runtime compilation return type of
task_with_optional_return
is Promise.
s
Could you elaborate on your use-case? If you want to return an
Optional[FlyteFile]
from your task, why do you want to set the type to
FlyteFile
while returning the same in a dynamic workflow? Does your task always return a
FlyteFile
, meaning, is it not necessary to check for
None
return type?
j
oh I dont want to return an optional type for this workflow but there are other workflow that returns an Optional. I am re-using a task that returns
Optional[FlyteFile]
but the parent dynamic task will always return
Flytefile
.
s
I still don't understand. Your task is being used by multiple workflows and some amongst them return an
Optional[FlyteFile]
, correct? But there's this dynamic workflow where you want to return
FlyteFile
. How do you know beforehand if your task is going to return a
FlyteFile
or a
None
?
j
sorry for the confusion. So task im trying to use in multiple places return
Optional[FlyteFile]
But the dynamic task im calling needs to just return
FlyteFile
this leads to validation error and i have to create a wrapper task that takes input as
Optional[FlyteFile]
and return
FlyteFile
but that looks a bit ugly
im doing this for now
Copy code
@task
def make_concrete_type_task(in_file: Optional[FlyteFile]) -> FlyteFile:
    return in_file
s
Understood. I don't think it's possible to set the output type to
FlyteFile
in your dynamic workflow if the task's output that's being returned from the dynamic workflow is an
Optional[FlyteFile]
.
j
i see, so above is the only way to resolve this right
s
Yeah! I know it's not an optimal solution but I think it isn't right for Flyte to support it either. Does that make sense to you?
j
Yeah that makes sense