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

Jay Ganbat

04/03/2023, 11:17 PM
Hi all, so i have a task that returns a Dataclass and i want to refer to the field of that object in the workflow is it possible? for ex:
Copy code
@dataclass
@dataclass_json
class MyDataClass:
   name: str

@task
def my_task() -> MyDataClass:
   return MyDataclass object

@task
def another_task(name: str) -> str:
   return f"Hello {name}"


@workflow
def my_wf() -> None:
   result = my_task()
   another_task(name=result.name)
when i try the above, it says
'Promise' object has no attribute 'name'
i just didnt wanna give the whole object to the task, i just want 1 field from it 😅
k

Kevin Su

04/03/2023, 11:23 PM
unfortunately, you can’t get the name from promise. you could use dynamic workflow to workaround it. like @dynamic def d1(res: MyDataClass) -> None: another_task(name=res.name)
j

Jay Ganbat

04/03/2023, 11:42 PM
i see, do you think it would change in the future so that Promise knows the attrib of the underlying outputs and inputs
d

Dan Rammer (hamersaw)

04/04/2023, 1:13 PM
@Jay Ganbat we have had some small discussion surrounding this. The use-case can be either using individual fields of a dataclass or indexing into a list. The issue with dataclass support is that currently flytekit handles serialization / deserialization of data and the backend (ie. flytepropeller) is completely unaware of format. To add support for using individual fields we would need to add additional context to the data type. It is certainly something we can do in the future, but currently not very high priority.
j

Jay Ganbat

04/04/2023, 4:17 PM
gotcha, thank you for the detailed explanation 😄