Hi, I am struggling on using a DataclassTransforme...
# ask-the-community
k
Hi, I am struggling on using a DataclassTransformer on a dataclass of the following shape:
Copy code
@dataclass_json
@dataclass
class WFConfig:
    some_key: Dict[int, List[int]] = field(default_factory=lambda: {1: [2, 3, 4]})
This works on a remote execution, but not locally using the flytekit TypeEngine as in the following example, which raises the error ValueError: Only generic univariate typing.List[T] type is supported.
Copy code
from dataclasses import dataclass, field
from typing import List, Dict

import flytekit
from dataclasses_json import dataclass_json
from flytekit.core.type_engine import TypeEngine


@dataclass_json
@dataclass
class WFConfig:
    some_key: Dict[int, List[int]] = field(default_factory=lambda: {1: [2, 3, 4]})


config = WFConfig()
transformer = TypeEngine.get_transformer(type(config))
flyte_context = flytekit.FlyteContextManager.current_context()

literal_type = transformer.get_literal_type(type(config))
literal = transformer.to_literal(flyte_context, config, type(config), literal_type)

python_type = transformer.guess_python_type(literal_type)
TypeEngine.to_python_value(flytekit.FlyteContextManager.current_context(), literal, python_type)
To me it seems like the python type could not be guessed correctly from the literal type. Does anyone have an Idea how I could fix this, or is this special composition of dict/list not supported? Thanks! I am working with flytekit 1.6.2
k
This is working right?
k
Does not work for me. Sorry for the confusing last line, I wanted to mention, that I am working with the version 1.6.2, not that the code is working.
k
Aah ok, got it. Cc @Kevin Su you might have the most context
g
Hi, not sure if this was resolved for you already, but I just ran into the same issue. The cause was that I had a dataclass with name `workflow`:
Copy code
@dataclass_json
@dataclass
class WorkflowConfig:
    workflow: dict = field(default_factory=dict)
    env: Optional[dict] = field(default_factory=dict)
    model: Optional[dict] = field(default_factory=dict)
Changing the
workflow
field name to anything else fixed the issue for me.
117 Views