Untyped upsert of a bool search attribute is recorded as Int in workflow.info().typed_search_attributes
What happens
When a workflow calls the deprecated dictionary form of workflow.upsert_search_attributes with a bool value, the worker updates workflow.info().typed_search_attributes locally with a key of type Int instead of Bool. Looking the attribute up with SearchAttributeKey.for_bool(...) then returns None, even though the server stores it as a Bool.
What should happen
The local typed view should use SearchAttributeKey.for_bool(name) for a [True] or [False] value, the same way it already guesses Keyword, Int, Double and Datetime for the other value types.
Minimal repro
bool_key = SearchAttributeKey.for_bool("MyBool") # registered as Bool on the server
@workflow.defn
class ReproWorkflow:
@workflow.run
async def run(self) -> None:
await asyncio.Future()
@workflow.signal
def upsert(self) -> None:
workflow.upsert_search_attributes({bool_key.name: [True]})
@workflow.query
def typed(self) -> str:
attrs = workflow.info().typed_search_attributes
return repr([(p.key.indexed_value_type.name, p.value) for p in attrs]) + " " + repr(attrs.get(bool_key))
After sending upsert and querying typed, the result is [('INT', True)] None. Expected [('BOOL', True)] True.
The same thing is visible directly:
>>> SearchAttributeKey._guess_from_untyped_values("MyBool", [True])
_SearchAttributeKey(_name='MyBool', _indexed_value_type=<SearchAttributeIndexedValueType.INT: 3>, _value_type=<class 'int'>)
Root cause
SearchAttributeKey._guess_from_untyped_values in temporalio/common.py checks isinstance(vals[0], int) before isinstance(vals[0], bool). Since bool is a subclass of int, the bool branch is never reached. The existing test_workflow_search_attributes test does not catch this because its query helper only compares key names and stringified values, not key types.
SDK version: main at da79461. Python 3.14.5, macOS arm64.
Is this something you are running into in a real user scenario, or a speculative bugfix? Given that it is a deprecated API, and the potential for breaking existing workflows which rely on this behavior, I'm inclined not to fix it.
Speculative, I found it reading the converter code rather than in a real workflow. Given the deprecated API and the replay risk, not fixing it makes sense. Closing the PR, thanks for looking.