-
Notifications
You must be signed in to change notification settings - Fork 61
[flyteidl] Support attribute access on promises #439
Conversation
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #439 +/- ##
==========================================
+ Coverage 75.92% 78.48% +2.55%
==========================================
Files 18 18
Lines 1458 1250 -208
==========================================
- Hits 1107 981 -126
+ Misses 294 212 -82
Partials 57 57
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: byhsu <[email protected]>
Signed-off-by: byhsu <[email protected]>
8542cc6
to
4e0aa0b
Compare
* init Signed-off-by: byhsu <[email protected]> * fix typo Signed-off-by: byhsu <[email protected]> --------- Signed-off-by: byhsu <[email protected]> Co-authored-by: byhsu <[email protected]>
Update 2023/10/14: After a discussion with @wild-endeavor, we want to perform strong type check for fields in dataclasses. For example, @dataclass
class Foo:
a: int
@task
def t0() -> Foo:
return Foo(a=1)
@task
def t1(x: str):
...
@workflow
def wf():
f = to()
t1(x=f.a) In the original implementation, In order to do type check for dataclass field, I added On the flytekit side, I constructed Related Code Changes:
I also conducted e2e test to ensure the behavior. In the following example, the workflow failed at compile time because of mismatched type.
|
TL;DR
Support attribute access on output promises for List, Dict, Dataclass, and the mix of them. After the change, users are able to pass in an attribute of output in the workflow, for example:
Type
Are all requirements met?
Complete description
1. Add attribute path on promise
__getitem__
and__getattr__
in class promise2. Compile Validation at flytepropeller
Skip the type check if the promise contains attribute path because if the type is dataclass, we have no way to infer the resolved type.
3. Execution
Local Execution:
In flytekit, Resolve the attribute path in translate_input_to_literals.
Remote Execution:
In flytepropeller, Resolve the attribute path in Extract_Output.
Although in different places, the logic is the same. It iterates the attribute path
If the remaining val is a LiteralScalar and it contains Dataclass, then iterate the remaining path to extract the value from dataclass.
The resolved result of dataclass can be dataclass, list, or a scalar.
Testing
In the following workflow:
basic_workflow
contains trivial examples to access output attributesfailed_workflow
contains examples that causes exception (e.g. out of range)advanced_workflow
contains examples with more complex attribute accessLocal Execution
Remote Execution
Tracking Issue
flyteorg/flyte#3864