Skip to content

Commit e543e8a

Browse files
authored
fix: typed search contains should work for falsy values (#1206)
1 parent 4156856 commit e543e8a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

temporalio/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def __contains__(self, key: object) -> bool:
496496
497497
This uses key equality so the key must be the same name and type.
498498
"""
499-
return any(v for k, v in self if k == key)
499+
return any(k == key for k, v in self)
500500

501501
@overload
502502
def get(

tests/test_common.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ def test_typed_search_attribute_duplicates():
9999
)
100100

101101

102+
def test_typed_search_attributes_contains_with_falsy_value():
103+
int_key = SearchAttributeKey.for_int("my-int")
104+
attrs = TypedSearchAttributes([SearchAttributePair(int_key, 0)])
105+
assert int_key in attrs
106+
107+
108+
def test_typed_search_attributes_contains_with_truthy_value():
109+
int_key = SearchAttributeKey.for_int("my-int")
110+
attrs = TypedSearchAttributes([SearchAttributePair(int_key, 42)])
111+
assert int_key in attrs
112+
113+
114+
def test_typed_search_attributes_contains_missing_key():
115+
int_key = SearchAttributeKey.for_int("my-int")
116+
missing_key = SearchAttributeKey.for_keyword("missing")
117+
attrs = TypedSearchAttributes([SearchAttributePair(int_key, 42)])
118+
assert missing_key not in attrs
119+
120+
102121
def test_cant_construct_bad_priority():
103122
with pytest.raises(TypeError):
104123
Priority(priority_key=1.1) # type: ignore

0 commit comments

Comments
 (0)