fix: handle unhashable partial handlers in param count cache

This commit is contained in:
Greyson LaLonde
2026-04-04 22:10:09 +08:00
parent 70fc701941
commit fac186a931

View File

@@ -11,11 +11,22 @@ from crewai.events.types.event_bus_types import AsyncHandler, SyncHandler
@functools.lru_cache(maxsize=256)
def _get_param_count(handler: Any) -> int:
"""Return the number of parameters a handler accepts, with caching."""
def _get_param_count_cached(handler: Any) -> int:
return len(inspect.signature(handler).parameters)
def _get_param_count(handler: Any) -> int:
"""Return the number of parameters a handler accepts, with caching.
Falls back to uncached introspection for unhashable handlers
like functools.partial.
"""
try:
return _get_param_count_cached(handler)
except TypeError:
return len(inspect.signature(handler).parameters)
def is_async_handler(
handler: Any,
) -> TypeIs[AsyncHandler]: