Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions sentry_sdk/integrations/pydantic_ai/patches/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overly broad except catches errors from patch functions

Medium Severity

The try/except AttributeError blocks catch exceptions from both the attribute access check and the _patch_execute_tool_call() / _patch_call_tool() calls. If a patching function raises AttributeError internally (e.g., from @wraps() or re-accessing the attribute), the error is silently swallowed. This could cause the integration to silently skip instrumentation or fall through to incorrectly patch the older _call_tool method. Using try/except/else would limit the catch scope to just the attribute probe.

Additional Locations (1)
Fix in Cursor Fix in Web


elif hasattr(ToolManager, "_call_tool"):
try:
ToolManager._call_tool
# older versions
_patch_call_tool()
return
except AttributeError:
pass


def _patch_execute_tool_call() -> None:
Expand Down
Loading