We've got a task that takes a list of DataClasses(...
# flyte-support
a
We've got a task that takes a list of DataClasses(see contrived example below), and are seeing this error - https://github.com/flyteorg/flytekit/blob/master/flytekit/core/type_engine.py#L1580. Can the
ListTransformer
be made to handle this case in the future? Or do we need to create a TypeTransformer specifically for
list[Foo]
?
Copy code
@dataclass_json
@dataclass
class Foo:
    val: str

@task
def foos_task(foos: list[Foo]) -> None:
    ....
It's also really strange because we are definitely able to handle lists of dataclasses as workflow arguments we use for subworkflows without any issue
Copy code
@workflow
def sub_wf(foos: list[Foo]) -> None:
    ....
t
this should definitely work.
Untitled
this works without issue for me. what version of flytekit are you on?
a
You are right. I actually get the error with an Agent
Copy code
from flytekit import task, workflow

from agent import Foo, FooTask

foo_task = FooTask(name="foo_task")


@task
def foos_task(foos: list[Foo]) -> None:
    print(f"hi {foos}")


@workflow
def dc_wf(foos: list[Foo]) -> None:
    has_foos, foos = foo_task()
    foos_task(foos=foos)


if __name__ == "__main__":
    dc_wf([Foo(val="a"), Foo(val="b")])
and
Copy code
from dataclasses import dataclass
from typing import Any, Dict, Optional

from dataclasses_json import dataclass_json
from flyteidl.core.execution_pb2 import TaskExecution
from flytekit.configuration import SerializationSettings
from flytekit.core.base_task import PythonTask
from flytekit.core.interface import Interface
from flytekit.extend.backend.base_agent import (
    AgentRegistry,
    Resource,
    SyncAgentBase,
    SyncAgentExecutorMixin,
)
from flytekit.models.literals import LiteralMap
from flytekit.models.task import TaskTemplate


@dataclass_json
@dataclass
class Foo:
    val: str


class FooAgent(SyncAgentBase):
    def __init__(self) -> None:
        super().__init__(task_type_name="foo")

    async def do(
        self,
        task_template: TaskTemplate,
        inputs: Optional[LiteralMap] = None,
        **kwargs: Any,
    ) -> Resource:
        return Resource(
            phase=TaskExecution.SUCCEEDED, outputs={"has_foos": True, "foos": [Foo(val="a"), Foo(val="b")]}
        )


AgentRegistry.register(FooAgent())


class FooTask(SyncAgentExecutorMixin, PythonTask):  # type: ignore
    _TASK_TYPE = "foo"

    def __init__(self, name: str, **kwargs: Any) -> None:
        task_config: dict[str, Any] = {}

        outputs = {"has_foos": bool, "foos": Optional[list[Foo]]}

        super().__init__(
            task_type=self._TASK_TYPE,
            name=name,
            task_config=task_config,
            interface=Interface(outputs=outputs),
            **kwargs,
        )

    def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]:
        return {}
I assumed the error was from the task, but it's actually before that
Yea, I just don't quite understand what's happening here
@thankful-minister-83577 any thoughts on this?
t
looking
kevin will clean up some of the error handling here.
and there’s one bug with the typing not getting passed.
but yeah the name of the output was wrong, i see you fixed that.
and lastly you are passing an optional list to a list, that’s not allowed.
if you try to register that against admin it will raise an error.
a
and there’s one bug with the typing not getting passed.
Is this what's most likely causing my issue?
Yea, the code was hastily thrown together yesterday to try and get an example for you all. Definitely some clean up 🙂
t
will be in 14 and probably backported to 13.x
a
sweet!
thank you so much
t
thank you for the bug report 🙇