Skip to content

fix run sync test

2fb567c
Select commit
Loading
Failed to load commit list.
Merged

fix(pydantic-ai): Use first-class hooks when available #5947

fix run sync test
2fb567c
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed Apr 9, 2026 in 7m 53s

1 issue

find-bugs: Found 1 issue (1 medium)

Medium

Span resource leak when ctx.metadata is not a dict - `sentry_sdk/integrations/pydantic_ai/__init__.py:50-52`

In on_request, the span is unconditionally entered via span.__enter__() at line 50, but the span is only stored in metadata if isinstance(run_context_metadata, dict) is True (lines 47-48). If metadata is not a dict (e.g., user passes a non-dict metadata value or pydantic-ai provides a different type), the span will be entered but never exited in on_response or on_error, causing a span resource leak. While the agent_run wrappers try to set metadata to a dict, they only do so if not metadata (falsy), so a truthy non-dict value would still trigger this bug.


Duration: 7m 51s · Tokens: 2.0M in / 25.5k out · Cost: $3.06 (+fix_gate: $0.00)

Annotations

Check warning on line 52 in sentry_sdk/integrations/pydantic_ai/__init__.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

Span resource leak when ctx.metadata is not a dict

In `on_request`, the span is unconditionally entered via `span.__enter__()` at line 50, but the span is only stored in metadata if `isinstance(run_context_metadata, dict)` is True (lines 47-48). If metadata is not a dict (e.g., user passes a non-dict metadata value or pydantic-ai provides a different type), the span will be entered but never exited in `on_response` or `on_error`, causing a span resource leak. While the agent_run wrappers try to set metadata to a dict, they only do so if `not metadata` (falsy), so a truthy non-dict value would still trigger this bug.