Skip to content

Commit f9ce14c

Browse files
fix: handle unhashable types in TypeAdapter cache without skipping validation
1 parent 2c808f8 commit f9ce14c

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/google/adk/tools/function_tool.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ def _preprocess_args(
132132
# Validate and coerce using TypeAdapter. Handles primitives, enums,
133133
# Pydantic models, Optional[T], T | None, and container types natively.
134134
try:
135-
if target_type not in self._type_adapter_cache:
136-
self._type_adapter_cache[target_type] = pydantic.TypeAdapter(
137-
target_type
138-
)
139-
adapter = self._type_adapter_cache[target_type]
135+
try:
136+
adapter = self._type_adapter_cache[target_type]
137+
except (KeyError, TypeError):
138+
adapter = pydantic.TypeAdapter(target_type)
139+
try:
140+
self._type_adapter_cache[target_type] = adapter
141+
except TypeError:
142+
pass
140143
converted_args[param_name] = adapter.validate_python(
141144
args[param_name]
142145
)

0 commit comments

Comments
 (0)