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

Skip to content

[Bug] Serializing Literal fails #852

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

Closed
brandonchinn178 opened this issue Apr 29, 2025 · 1 comment · Fixed by #867
Closed

[Bug] Serializing Literal fails #852

brandonchinn178 opened this issue Apr 29, 2025 · 1 comment · Fixed by #867
Labels
bug Something isn't working

Comments

@brandonchinn178
Copy link

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

@brandonchinn178 brandonchinn178 added the bug Something isn't working label Apr 29, 2025
@cretz
Copy link
Member

cretz commented Apr 30, 2025

Yes, this is a bug as we need to also check the stdlib Literal instead of just typing_extensions. Thanks for reporting, we will fix.

and perhaps replicate the deduplication logic in 3.10+

For our use at

# Literal
if origin is Literal:
if value not in type_args:
raise TypeError(f"Value {value} not in literal values {type_args}")
return value
the dedupe isn't really needed I think since we just do a validation check on the collection (regardless of whether it's in there multiple times) before accepting the raw value.

maciejdudko added a commit to maciejdudko/temporal-sdk-python that referenced this issue May 14, 2025
maciejdudko added a commit that referenced this issue May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants