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] Dataclass transformer errors when using frozen dataclasses #5849

Open
2 tasks done
ggydush opened this issue Oct 15, 2024 · 0 comments
Open
2 tasks done

[BUG] Dataclass transformer errors when using frozen dataclasses #5849

ggydush opened this issue Oct 15, 2024 · 0 comments
Assignees
Labels
bug Something isn't working flytekit FlyteKit Python related issue

Comments

@ggydush
Copy link

ggydush commented Oct 15, 2024

Describe the bug

Dataclass transformer does not work with frozen dataclasses

Expected behavior

Dataclass transformer should work with frozen dataclasses

Additional context to reproduce

from dataclasses import dataclass

from flytekit import task


@dataclass(frozen=True)
class DummyDataclass:
    x: int = 1


@task
def dummy_task(dc: DummyDataclass) -> int:
    return dc.x


if __name__ == "__main__":
    dummy_task(dc=DummyDataclass(x=1))
/Users/ggydush/dev/delve/clinical-pipeline/clinical_pipeline/core/dataclasses/tmp.py:17 in <module>                                                                             │
│                                                                                                                                                                                 │
│ ❱ 17 │   dummy_task(dc=DummyDataclass(x=1))                                                                                                                                     │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/base_task.py:358 in __call__                                           │
│                                                                                                                                                                                 │
│ ❱ 358 │   │   return flyte_entity_call_handler(self, *args, **kwargs)  # type: ignore                                                                                           │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/promise.py:1256 in flyte_entity_call_handler                           │
│                                                                                                                                                                                 │
│ ❱ 1256 │   │   │   result = cast(LocallyExecutable, entity).local_execute(child_ctx, **kwargs)                                                                                  │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/base_task.py:285 in local_execute                                      │
│                                                                                                                                                                                 │
│ ❱ 285 │   │   │   kwargs = translate_inputs_to_literals(                                                                                                                        │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/promise.py:95 in translate_inputs_to_literals                          │
│                                                                                                                                                                                 │
│ ❱   95 │   │   │   result[k] = TypeEngine.to_literal(ctx, v, t, var.type)                                                                                                       │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/type_engine.py:1174 in to_literal                                      │
│                                                                                                                                                                                 │
│ ❱ 1174 │   │   lv = transformer.to_literal(ctx, python_val, python_type, expected)                                                                                              │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/type_engine.py:485 in to_literal                                       │
│                                                                                                                                                                                 │
│ ❱  485 │   │   self._serialize_flyte_type(python_val, python_type)                                                                                                              │
│                                                                                                                                                                                 │
│ /Users/ggydush/.virtualenvs/clinical-pipeline-ErT9kUro-py3.11/lib/python3.11/site-packages/flytekit/core/type_engine.py:597 in _serialize_flyte_type                            │
│                                                                                                                                                                                 │
│ ❱  597 │   │   │   │   python_val.__setattr__(v.name, self._serialize_flyte_type(val, field_typ                                                                                 │
│ in __setattr__:4                                                                                                                                                                │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
FrozenInstanceError: cannot assign to field 'x'

Screenshots

No response

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

  • Yes

Have you read the Code of Conduct?

  • Yes
@ggydush ggydush added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Oct 15, 2024
@eapolinario eapolinario added flytekit FlyteKit Python related issue and removed untriaged This issues has not yet been looked at by the Maintainers labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flytekit FlyteKit Python related issue
Projects
Status: Backlog
Development

No branches or pull requests

3 participants