You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[cache] @cache raises TypeError for unhashable arguments (e.g. Pydantic model inputs) #59
In nitrostack/core/additional_decorators.py, @cache builds its cache key directly from positional and keyword arguments. When an argument is unhashable, such as a non-frozen Pydantic v2 model, the cache lookup raises TypeError instead of executing the function.
Findings
cache() filters out ExecutionContext arguments but retains other arguments in their original form.
The cache key is constructed using tuple(filtered_args) and frozenset(filtered_kwargs.items()). Both structures require their contents to be hashable.
When a Pydantic model is passed as an argument, checking whether the key exists in cache_store can raise TypeError: unhashable type.
This affects cached tool methods that receive Pydantic input models and other functions that accept unhashable arguments.
The current implementation does not provide a custom key function or a clear error explaining which argument caused the failure.
Proposal
Serialize Pydantic BaseModel arguments using model_dump(mode="json") and generate a deterministic cache key from the serialized data.
Add an optional key= callable to cache() so developers can define cache keys for custom argument types.
Raise a clear, descriptive error identifying the unhashable argument and its type when a valid cache key cannot be constructed.
Add tests covering Pydantic models, unhashable positional and keyword arguments, and custom key functions.
Fixed by #110 (merge ca3e7b8 on develop). Verified both cases from the review: exclude=True fields are part of the cache key, and same-named models from different scopes no longer collide. Full suite on develop @ 331bebe: 1338 passed.
Activity
manish-wekan commentedon Nov 5, 2026
Fixed by #110 (merge
ca3e7b8ondevelop). Verified both cases from the review:exclude=Truefields are part of the cache key, and same-named models from different scopes no longer collide. Full suite ondevelop@331bebe: 1338 passed.~sent from claude-code