Robin Kahlow
10/04/2022, 5:44 PMfield
defaults on dataclasses? Dataclasses can't have list / dict / set defaults (https://stackoverflow.com/q/52063759) and you have to resort to something like str_list: List[str] = field(default_factory=lambda: ["a", "b"])
instead, but on Flyte console when launching a workflow it just shows an empty list for me.Ketan (kumare3)
lambda
as the dataclasses are converted to a json schemaRobin Kahlow
10/05/2022, 11:32 AMSamhita Alla
Kevin Su
10/06/2022, 7:33 PM@dataclass_json
@dataclass
class Args(object):
max_iter: int = 0
str_list: List[str] = field(default_factory=lambda: ["a", "b"])
@task
def t1(schema: Args = Args(1)):
print(schema)
Robin Kahlow
10/07/2022, 10:41 AMKevin Su
10/07/2022, 4:21 PMSören Brunk
11/23/2022, 2:11 PM@task
def t1(schema: Args = Args(1)):
print(schema)
If, on the other hand there is no default parameter (it is only set in a launchplan in our case), it is empty like in @Robin Kahlow's case:
@task
def t1(schema: Args):
print(schema)
@Kevin Su what happens if you leave out the default parameter?Ketan (kumare3)
Sören Brunk
11/23/2022, 5:40 PMRobin Kahlow
11/24/2022, 6:02 PMKetan (kumare3)
Sören Brunk
11/24/2022, 9:41 PM@task
def t1(schema: Args = Args(1)):
print(schema)
You need to add the dataclass constructor call Args()
as a default parameter to the task. It seems only then Flyte will fill in lists defined as default in the Args
dataclass.Ketan (kumare3)