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

fix(pydantic-ai): Only use hooks when ModelRequestContext.model is av…

825ebeb
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden completed Jun 2, 2026 in 3m 9s

2 issues

Medium

Version guard bypassed when `package_version` returns `None`, re-exposing the AttributeError - `sentry_sdk/integrations/pydantic_ai/__init__.py:168-175`

When package_version("pydantic-ai") returns None (e.g., missing package metadata), the version check short-circuits and the code falls through to register_hooks(hooks), which calls request_context.model — the exact attribute access the PR intends to gate behind >= 1.73. Consider treating a None version as if it is below the minimum safe version, or defaulting are_request_hooks_available to False in that case.

Version guard is skipped when `package_version` returns `None`, preserving the original `AttributeError` - `sentry_sdk/integrations/pydantic_ai/__init__.py:169-173`

When package_version("pydantic-ai") returns None, the condition PYDANTIC_AI_VERSION is not None and PYDANTIC_AI_VERSION < (1, 73) short-circuits to False, so _patch_graph_nodes() is skipped and the code falls through to use Hooks. On pydantic-ai 1.71–1.72 (which has Hooks but not ModelRequestContext.model), this still triggers the AttributeError this PR is meant to fix.

Also found at:

  • sentry_sdk/integrations/pydantic_ai/__init__.py:4
4 skills analyzed
Skill Findings Duration Cost
security-review 0 3.4s $0.02
code-review 1 1m 13s $0.22
find-bugs 1 2m 38s $0.37
skill-scanner 0 4.1s $0.02

⏱ 3m 59s · 135.8k in / 12.1k out · $0.64