Hey, can Flyte handle `field` defaults on dataclas...
# flyte-support
e
Hey, can Flyte handle
field
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.
f
I think i may be able to handle constants, definitely not
lambda
as the dataclasses are converted to a json schema
e
it should be possible to execute that default_factory to get the constant it returns though no?
t
cc: @glamorous-carpet-83516
šŸ‘€ 1
g
What flytekit version you are using?
str_list: List[str] = field(default_factory=lambda: ["a", "b"])
is working for me. Maybe share your code snippet can help.
My task
Copy code
@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)
e
I was using 1.1.1, but updated to 1.2.1 and have the same problem there. Was it filled in the launch workflow form for you too? // will try to make a repro later
g
yeah
šŸ‘€ 1
I’m using the latest version of sandbox
b
I just ran into this as well. I my case, the list is only filled if I actually have a default parameter that creates an instance of the dataclass.
Copy code
@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 @elegant-petabyte-32634's case:
Copy code
@task
def t1(schema: Args):
    print(schema)
@glamorous-carpet-83516 what happens if you leave out the default parameter?
f
So tasks do not support default parameters
This default is working on the python side
Only default supported is none
Cc @thankful-minister-83577 maybe we should have an error of this case
b
Interesting though that in this case Flyteconsole showing the list entries only seems to work with a default parameter on task and workflow šŸ¤”
šŸ‘† 1
e
nice to know, i still hadn't figured it out until you mentioned this
f
Wdym, default parameter on the task?
b
@freezing-airport-6809 like this:
Copy code
@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.
f
This is odd, I think this is because of json schema
160 Views