Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [flytekit] Task with input containing Enum inside dataclass fails when executing with flytekit remote access #6155

Open
2 tasks done
pimdh opened this issue Jan 9, 2025 · 2 comments
Labels
bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers

Comments

@pimdh
Copy link

pimdh commented Jan 9, 2025

Describe the bug

Consider following task definition:

from dataclasses import dataclass
from enum import Enum

from flytekit import FlyteRemote, task
from flytekit.configuration import Config

class B(Enum):
    X = "x"
    Y = "y"


@dataclass
class A:
    b: B


@task
def flyte_test_task(a: A) -> None:
    print(a)

Then register. Then execute with:

PROJECT = ...
DOMAIN = ...
remote = FlyteRemote(config=Config.auto())
task = remote.fetch_task(name="flyte_test_task", project=PROJECT, domain=DOMAIN)

execution = remote.execute(
    task,
    project=PROJECT,
    domain=DOMAIN,
    inputs={"a": A(b=B.X)},
)

This triggers error:

TypeTransformerFailedError: Type of Val '<enum 'B'>' is not an instance of <class 'str'>

If the enum is not inside a dataclass, but an argument to the task itself, the bug does not occur.

Expected behavior

The execution should be successfully created.

If instead I submit via the CLI

pyflyte run -p PROJECT -d DOMAIN remote-task flyte_test_task --a '{"b": "x"}'

The execution is created as expected.

Additional context to reproduce

Using flytekit version 1.14.3

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • Yes

Have you read the Code of Conduct?

  • Yes
@pimdh pimdh added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Jan 9, 2025
@pimdh
Copy link
Author

pimdh commented Jan 9, 2025

The issue to follow from to the guessing of the Python type from the Flyte Literal.
The literal has metadata:

{'additionalProperties': False,
 'properties': {'b': {'enum': ['x', 'y']}},
 'required': ['b'],
 'title': 'A',
 'type': 'object'}

But the inferred Python dataclass type is flytekit.core.type_engine.A with field Field(name='b',type=<class 'str'>, ...). This should've been the Enum, instead of a string. This issue is caused by this code.

@pimdh
Copy link
Author

pimdh commented Jan 10, 2025

There is an easy work-around for this bug by just providing the type hint:

execution = remote.execute(
    task,
    project=PROJECT,
    domain=DOMAIN,
    inputs={"a": A(b=B.X)},
    type_hints:{"a": A}, 
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers
Projects
Status: Backlog
Development

No branches or pull requests

1 participant