From fac186a931c36f0314a433ee3c11d7f54f3c0225 Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Sat, 4 Apr 2026 22:10:09 +0800 Subject: [PATCH] fix: handle unhashable partial handlers in param count cache --- lib/crewai/src/crewai/events/utils/handlers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/crewai/src/crewai/events/utils/handlers.py b/lib/crewai/src/crewai/events/utils/handlers.py index 386da6b47..48d21bd75 100644 --- a/lib/crewai/src/crewai/events/utils/handlers.py +++ b/lib/crewai/src/crewai/events/utils/handlers.py @@ -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]: