Skip to content

fix(pydantic-ai): Only use hooks when ModelRequestContext.model exists#6480

Merged
alexander-alderman-webb merged 8 commits into
masterfrom
webb/pydantic-ai/hooks-version-gate
Jun 2, 2026
Merged

fix(pydantic-ai): Only use hooks when ModelRequestContext.model exists#6480
alexander-alderman-webb merged 8 commits into
masterfrom
webb/pydantic-ai/hooks-version-gate

.

4dbb8bf
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: code-review completed Jun 2, 2026 in 4m 36s

1 issue

code-review: Found 1 issue (1 medium)

Medium

`are_request_hooks_available` not reset to `False` when version < 1.73 but `Hooks` is importable - `sentry_sdk/integrations/pydantic_ai/__init__.py:12`

When pydantic-ai-slim is installed at a version < 1.73 but the Hooks class can be imported, setup_once() calls _patch_graph_nodes() and returns without registering hooks — but are_request_hooks_available remains True. This causes agent_run.py wrappers (lines 112, 161) to inject {"_sentry_span": None} into every agent run's metadata even though no hook will ever populate that span. Consider setting PydanticAIIntegration.are_request_hooks_available = False before returning in the version-check branch.

Also found at:

  • sentry_sdk/integrations/pydantic_ai/__init__.py:183-184

⏱ 3m 51s · 210.5k in / 11.6k out · $0.52

Annotations

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

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

`are_request_hooks_available` not reset to `False` when version &lt; 1.73 but `Hooks` is importable

When `pydantic-ai-slim` is installed at a version &lt; 1.73 but the `Hooks` class can be imported, `setup_once()` calls `_patch_graph_nodes()` and returns without registering hooks — but `are_request_hooks_available` remains `True`. This causes `agent_run.py` wrappers (lines 112, 161) to inject `{"_sentry_span": None}` into every agent run's metadata even though no hook will ever populate that span. Consider setting `PydanticAIIntegration.are_request_hooks_available = False` before returning in the version-check branch.

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

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

[2QY-TMW] `are_request_hooks_available` not reset to `False` when version &lt; 1.73 but `Hooks` is importable (additional location)

When `pydantic-ai-slim` is installed at a version &lt; 1.73 but the `Hooks` class can be imported, `setup_once()` calls `_patch_graph_nodes()` and returns without registering hooks — but `are_request_hooks_available` remains `True`. This causes `agent_run.py` wrappers (lines 112, 161) to inject `{"_sentry_span": None}` into every agent run's metadata even though no hook will ever populate that span. Consider setting `PydanticAIIntegration.are_request_hooks_available = False` before returning in the version-check branch.