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: find-bugs completed Jun 2, 2026 in 3m 4s

1 issue

find-bugs: Found 1 issue (1 medium)

Medium

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

⏱ 2m 38s · 66.4k in / 8.4k out · $0.37

Annotations

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

See this annotation in the file changed.

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

Version guard is skipped when `package_version` returns `None`, preserving the original `AttributeError`

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.

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

See this annotation in the file changed.

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

[QW6-GBZ] Version guard is skipped when `package_version` returns `None`, preserving the original `AttributeError` (additional location)

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.