Hi all, so i have a task that returns a Dataclass ...
# ask-the-community
j
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
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
i see, do you think it would change in the future so that Promise knows the attrib of the underlying outputs and inputs
d
@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
gotcha, thank you for the detailed explanation 😄
150 Views