From bcae6267aa2685a1cb6d87942156a03988bfa734 Mon Sep 17 00:00:00 2001 From: BillionClaw <267901332+BillionClaw@users.noreply.github.com> Date: Wed, 18 Mar 2026 19:51:22 +0800 Subject: [PATCH] fix(pydantic_ai): Fix AttributeError when patching ToolManager methods The _patch_tool_execution() function used hasattr() to check for method existence, but this can return True even when accessing the attribute raises AttributeError (e.g., for properties). This caused a regression in 2.55.0 when using pydantic-ai 1.69.0+. Now we try to access the method directly in a try-except block to safely handle cases where the method doesn't exist or raises AttributeError. Fixes #5686 --- .../integrations/pydantic_ai/patches/tools.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/pydantic_ai/patches/tools.py b/sentry_sdk/integrations/pydantic_ai/patches/tools.py index 1f5cde8742..f5db02c215 100644 --- a/sentry_sdk/integrations/pydantic_ai/patches/tools.py +++ b/sentry_sdk/integrations/pydantic_ai/patches/tools.py @@ -28,12 +28,22 @@ def _patch_tool_execution() -> None: - if hasattr(ToolManager, "execute_tool_call"): + # Try to access the method directly, as hasattr() can return True + # but accessing the attribute may still raise AttributeError (e.g., for properties) + try: + ToolManager.execute_tool_call _patch_execute_tool_call() + return + except AttributeError: + pass - elif hasattr(ToolManager, "_call_tool"): + try: + ToolManager._call_tool # older versions _patch_call_tool() + return + except AttributeError: + pass def _patch_execute_tool_call() -> None: