Skip to content

Commit 9bdf8ea

Browse files
committed
fix: use origin identity check for types.UnionType in _unwrap_optional
1 parent 0fa7d25 commit 9bdf8ea

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/uipath_langchain/agent/react/json_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _unwrap_optional(annotation: Any) -> Any:
184184
The unwrapped type, or the original if not Optional/Union
185185
"""
186186
origin = get_origin(annotation)
187-
if origin is Union or isinstance(annotation, types.UnionType):
187+
if origin is Union or origin is types.UnionType:
188188
args = get_args(annotation)
189189
non_none_args = [arg for arg in args if arg is not type(None)]
190190
if non_none_args:

tests/agent/react/test_json_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class WithOptional(BaseModel):
2727
target: Optional[Target] = None
2828

2929

30+
class WithPipeUnion(BaseModel):
31+
target: Target | None = None
32+
33+
3034
class WithNestedList(BaseModel):
3135
matrix: list[list[Target]]
3236

@@ -54,6 +58,10 @@ def test_optional_field(self):
5458
paths = get_json_paths_by_type(WithOptional, "Target")
5559
assert paths == ["$.target"]
5660

61+
def test_pipe_union_field(self):
62+
paths = get_json_paths_by_type(WithPipeUnion, "Target")
63+
assert paths == ["$.target"]
64+
5765
def test_nested_list_of_lists(self):
5866
paths = get_json_paths_by_type(WithNestedList, "Target")
5967
assert paths == ["$.matrix[*][*]"]

0 commit comments

Comments
 (0)