Skip to content

Commit 8544ab9

Browse files
fix: handle unhashable types in TypeAdapter cache without skipping validation
1 parent 31c5dc2 commit 8544ab9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/google/adk/tools/function_tool.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ def _preprocess_args(
135135
# Validate and coerce using TypeAdapter. Handles primitives, enums,
136136
# Pydantic models, Optional[T], T | None, and container types natively.
137137
try:
138-
if target_type not in self._type_adapter_cache:
139-
self._type_adapter_cache[target_type] = pydantic.TypeAdapter(
140-
target_type
141-
)
142-
adapter = self._type_adapter_cache[target_type]
138+
try:
139+
adapter = self._type_adapter_cache[target_type]
140+
except (KeyError, TypeError):
141+
adapter = pydantic.TypeAdapter(target_type)
142+
try:
143+
self._type_adapter_cache[target_type] = adapter
144+
except TypeError:
145+
pass
143146
converted_args[param_name] = adapter.validate_python(
144147
args[param_name]
145148
)

0 commit comments

Comments
 (0)