Richard Li
08/23/2023, 5:54 PMdataclass
? We're looking into modifying flytekit/core/promise.py for example. I just wanted to confirm first if this functionality is even possible. Anotehr concern I have is what happens when a class contains another class as an attribute. It seems that not even NamedTuple supports this atm.Kevin Su
08/23/2023, 6:07 PM@dataclass_json
@dataclass
class Person:
name: str
nationality: str
@task
def create_person(name: str, nationality: str) -> Person:
return Person(name=name, nationality=nationality)
@task
def say_hello(name: str) -> str:
greeting = f"hello {name}"
print(greeting)
return greeting
@workflow
def my_wf(name: str="aria", nationality:str="Indonesian") -> str:
person = create_person(name=name, nationality=nationality)
return say_hello(name=person.name). --> throws AttributeError: 'Promise' object has no attribute 'name'
Richard Li
08/23/2023, 6:13 PMKevin Su
08/23/2023, 8:07 PMRichard Li
08/23/2023, 8:12 PMKevin Su
08/23/2023, 8:39 PMmessage OutputReference {
// Node id must exist at the graph layer.
string node_id = 1;
// Variable name must refer to an output variable for the node.
string var = 2;
Dataclass dataclass_var = 3;
}
message Dataclass {
string var1 = 1;
Dataclass var2 = 2;
}
Yee
Byron Hsu
08/23/2023, 9:22 PMRichard Li
08/23/2023, 9:25 PMByron Hsu
08/23/2023, 9:26 PMattribute
fields to the promise class. In the above case, promise x
looks some like Promise(NodeOutput=(t1, d), attribute".x")
2. On the flytepropeller side, in extractOutput, where the promise got resolved, access the attribute on the dataclass. dataclass is serialized as protobuf struct, so should be able to access the field by simply .x
or somethingYee
Byron Hsu
08/23/2023, 9:26 PMYee
Byron Hsu
08/23/2023, 9:26 PMi don’t think this will be done in a week though.the plan is just to get a design or poc
Yee
Byron Hsu
08/23/2023, 9:26 PMYee
Byron Hsu
08/23/2023, 9:27 PMthis is for everything that’s json serializable right?yes
Yee
Byron Hsu
08/23/2023, 9:27 PMYee
Byron Hsu
08/23/2023, 9:54 PMRichard Li
08/23/2023, 10:02 PMByron Hsu
08/23/2023, 10:03 PMYee