https://flyte.org logo
#ask-the-community
Title
# ask-the-community
j

Jannis

04/19/2023, 7:33 AM
Hey everyone. Just a quick question. Does someone know if there is the a proper way to handle keywordarguments with tasks:
Copy code
@task
def test(a, b, c):
    return a+b+c

@workflow
def workflow_test():
    kwargs = {"a": 4, "b": 3, "c":0}
    test(**kwargs)
Thanks already!
j

Jay Ganbat

04/19/2023, 9:33 AM
i think what you have should work right? do you want to return a dict and give that to the next task since just having the hard coded values here is not very useful
j

Jannis

04/19/2023, 11:24 AM
You are right. My example was a bit off. Let me draw a better one:
Copy code
@task
def task1():
    return {"a": 4, "b": 3, "c":0}

@task
def task2(a, b, c):
    return a+b+c

@workflow
def workflow_test():
    kwargs = task1()
    task2(**kwargs)
Basically lets say task1 returns a dictionary with optimal parameters for initating task2.
Since the kwargs returned will be a Promise it basically cant be used in this way
j

Jay Ganbat

04/19/2023, 11:56 AM
yeah, what we have for this case was just return a
dict
and recieve a dict like this
Copy code
def my_task(task_params: dict):
and return
dict ->:
in other task, well we dont do exactly what you have in your example but it should work
j

Jannis

04/19/2023, 11:57 AM
Okay so if I understand you correcty you then map the parameters from the dict inside the function?
j

Jay Ganbat

04/19/2023, 11:57 AM
yup `MyObject(**task_params)`and use the object
j

Jannis

04/19/2023, 11:58 AM
I see thanks a lot!
67 Views