Hi all, so i have a task that returns a Dataclass ...
# ask-the-community
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
class MyDataClass:
   name: str

def my_task() -> MyDataClass:
   return MyDataclass object

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

def my_wf() -> None:
   result = my_task()
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 😅
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)
i see, do you think it would change in the future so that Promise knows the attrib of the underlying outputs and inputs
@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.
gotcha, thank you for the detailed explanation 😄