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
1 change: 1 addition & 0 deletions changelog/fixed/rounded-pebble-skipping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep whole-number `Double` values in typed search attributes returned by `list_workflows()` and other visibility results, instead of silently dropping them.
10 changes: 9 additions & 1 deletion temporalio/converter/_search_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections.abc import Sequence
from datetime import datetime
from typing import Any

import temporalio.api.common.v1
import temporalio.common
Expand Down Expand Up @@ -182,7 +183,7 @@ def decode_typed_search_attributes(
)
if not key:
continue
val = conv.from_payload(v)
val: Any = conv.from_payload(v)
# If the value is a list but the type is not keyword list, pull out
# single item or consider this an invalid value and ignore
if (
Expand All @@ -200,6 +201,13 @@ def decode_typed_search_attributes(
parser = _get_iso_datetime_parser()
# We will let this throw
val = parser(val)
elif (
key.indexed_value_type
== temporalio.common.SearchAttributeIndexedValueType.DOUBLE
and type(val) is int
):
# Visibility returns a whole-number Double as a JSON integer
val = float(val)
# If the value isn't the right type, we need to ignore
if isinstance(val, key.origin_value_type):
pairs.append(temporalio.common.SearchAttributePair(key, val))
Expand Down
17 changes: 17 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
TransferTypeConverter,
create_payload_validation_error,
decode_search_attributes,
decode_typed_search_attributes,
encode_search_attribute_values,
encode_typed_search_attribute_value,
transfer_type_convertible,
Expand Down Expand Up @@ -488,6 +489,22 @@ def test_encode_typed_search_attribute_value_datetime_requires_timezone():
assert payload.metadata["type"] == b"Datetime"


def test_decode_typed_search_attributes_whole_number_double():
# Visibility returns a whole-number Double as a JSON integer
key = temporalio.common.SearchAttributeKey.for_float("score")
api = temporalio.api.common.v1.SearchAttributes(
indexed_fields={
"score": temporalio.api.common.v1.Payload(
data=b"5",
metadata={"type": b"Double", "encoding": b"json/plain"},
)
}
)
val = decode_typed_search_attributes(api).get(key)
assert val == 5.0
assert type(val) is float


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

Expand Down
Loading