fix(pydantic-ai): Only use hooks when ModelRequestContext.model exists#6480
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
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
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.