Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug] Serializing Literal fails #852

Closed
@brandonchinn178

Description

@brandonchinn178

What are you really trying to do?

Use a dataclass as activity input with a field of type Literal["success", "failure"]

Describe the bug

When using the Literal type_hint, value_to_type shows an error

Unserializable type during conversion: typing.Literal['success', 'failure']

This seems to happen because temporal checks referential equality with Literal from typing_extensions, but typing_extensions doesnt reuse the one from typing unless 3.10+

Workaroundable by using Literal from typing_extensions, but this isnt documented. It would be nice if temporal just used the normal Literal from typing (and perhaps replicate the deduplication logic in 3.10+)

Minimal Reproduction

python3.9 -m venv venv
venv/bin/pip install temporalio
venv/bin/python

from temporalio.converter import value_to_type
from typing import *
value_to_type(Literal["a", "b"], "a")

Environment/Versions

  • OS and processor: [e.g. M1 Mac, x86 Windows, Linux]
  • Temporal Version: [e.g. 1.14.0?] and/or SDK version
  • Are you using Docker or Kubernetes or building Temporal from source?

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions