I am running into a predicament when I use datacla...
# ask-the-community
e
I am running into a predicament when I use dataclasses for params. Sometimes, I want to pass in the entire dataclass into a task, other times I want to reference a specific field. I have explored two options: • Have a task that converts a dataclass to a named tuple • Use @dynamic workflows Using dynamic workflows works, but maybe there are side effects? I would love to learn from folks who have gone down this path before.
Copy code
from flytekit import workflow, dynamic, task

@dataclass_json
@dataclass
class Params:
    color: str

@task
def print_color(c: str):
    print(c)
    
@dynamic
def wf(params: Params) -> Params:
    print_color(c=params.color)
    return inner
k
Cc @Ankit Goyal I think Ankit and team offered to implement this in Flyte
So @Evan Sadler I think we will support this in native Flyte in sometime
d
For some context - this conversation. Basically, we could encode the Flyte
Literal
as a field of the dataclass rather than just the dataclass itself, then propeller internally can parse and retrieve the field when passing input values. I'm convinced it would be possible.
Then you wouldn't need to use a dynamic workflow here and incur the overhead of starting a separate Pod just to retrieve the field value from your Params dataclass. Propeller could parse it directly.
e
Oh nice! Looking forward to it 🙂.
157 Views