fix(pydantic-ai): Only use hooks when ModelRequestContext.model exists#6480
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
sentry-warden / warden: code-review
`are_request_hooks_available` not reset to `False` when version < 1.73 but `Hooks` is importable
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.
Check warning on line 184 in sentry_sdk/integrations/pydantic_ai/__init__.py
sentry-warden / warden: code-review
[2QY-TMW] `are_request_hooks_available` not reset to `False` when version < 1.73 but `Hooks` is importable (additional location)
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.