lemon-gold-32767
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.glamorous-carpet-83516
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'
lemon-gold-32767
08/23/2023, 6:13 PMglamorous-carpet-83516
08/23/2023, 8:07 PMlemon-gold-32767
08/23/2023, 8:12 PMglamorous-carpet-83516
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;
}
thankful-minister-83577
polite-ability-4005
08/23/2023, 9:22 PMlemon-gold-32767
08/23/2023, 9:25 PMpolite-ability-4005
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 somethingthankful-minister-83577
polite-ability-4005
08/23/2023, 9:26 PMthankful-minister-83577
polite-ability-4005
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
thankful-minister-83577
polite-ability-4005
08/23/2023, 9:26 PMpolite-ability-4005
08/23/2023, 9:26 PMthankful-minister-83577
polite-ability-4005
08/23/2023, 9:27 PMthis is for everything that’s json serializable right?yes
thankful-minister-83577
polite-ability-4005
08/23/2023, 9:27 PMthankful-minister-83577
polite-ability-4005
08/23/2023, 9:54 PMpolite-ability-4005
08/23/2023, 9:54 PMlemon-gold-32767
08/23/2023, 10:02 PMpolite-ability-4005
08/23/2023, 10:03 PMthankful-minister-83577