Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion temporalio/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,9 @@ def value_to_type(
elif key_type is type(None):
key = {"null": None}[key]

if not isinstance(key, key_type):
# Can't call isinstance of key_type is a newtype
supertype = getattr(key_type, "__supertype__", None)
if supertype or not isinstance(key, key_type):
key = value_to_type(key_type, key, custom_converters)
except Exception as err:
raise TypeError(
Expand Down
25 changes: 25 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
_JSONTypeConverterUnhandled,
decode_search_attributes,
encode_search_attribute_values,
value_to_type,
)
from temporalio.exceptions import ApplicationError, FailureError

Expand Down Expand Up @@ -91,6 +92,14 @@ class DatetimeClass:
datetime: datetime


MyNewTypeStr = NewType("MyNewTypeStr", str)


@dataclass
class NewTypeMessage:
data: dict[MyNewTypeStr, str]


async def test_converter_default():
async def assert_payload(
input,
Expand Down Expand Up @@ -215,6 +224,22 @@ async def assert_payload(
type_hint=DatetimeClass,
)

# Newtype String
await assert_payload(
MyNewTypeStr("somestr"),
"json/plain",
'"somestr"',
type_hint=MyNewTypeStr,
)

# Newtype String key
await assert_payload(
NewTypeMessage({MyNewTypeStr("key"): "value"}),
"json/plain",
'{"data":{"key":"value"}}',
type_hint=NewTypeMessage,
)


def test_binary_proto():
# We have to test this separately because by default it never encodes
Expand Down
Loading