Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ to include examples, links to docs, or any other relevant information.

### Fixed

- Encoding a datetime search attribute without a timezone now raises
`ValueError("Timezone must be present on all search attribute dates")` on
the typed path, matching the deprecated untyped encoder, instead of sending
a naive ISO string that the server rejects with `BadSearchAttributes`.
- Restore pickling of Pydantic data converters, preserving the type adapter cache
size limit while excluding cached adapters.
- Current workflow and activity payload converter accessors now return the configured converter
Expand Down
2 changes: 2 additions & 0 deletions temporalio/converter/_search_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def encode_typed_search_attribute_value(
)
# datetime needs to be in isoformat
if isinstance(value, datetime):
if value.tzinfo is None:
raise ValueError("Timezone must be present on all search attribute dates")
value = value.isoformat()
# We'll do an extra sanity check for keyword list and check every value
if isinstance(value, Sequence):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
create_payload_validation_error,
decode_search_attributes,
encode_search_attribute_values,
encode_typed_search_attribute_value,
transfer_type_convertible,
value_to_type,
)
Expand Down Expand Up @@ -467,6 +468,18 @@ def test_encode_search_attribute_values():
encode_search_attribute_values(["foo", 123]) # type: ignore[arg-type]


def test_encode_typed_search_attribute_value_datetime_requires_timezone():
key = temporalio.common.SearchAttributeKey.for_datetime("checkout_time")
with pytest.raises(ValueError, match="Timezone must be present"):
encode_typed_search_attribute_value(
key, datetime(2024, 7, 5, 15, 43, 7, 875302)
)
payload = encode_typed_search_attribute_value(
key, datetime(2024, 7, 5, 15, 43, 7, 875302, tzinfo=timezone.utc)
)
assert payload.metadata["type"] == b"Datetime"


def test_decode_search_attributes():
"""Tests decode from protobuf for python types"""

Expand Down
Loading