Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions sentry_sdk/integrations/pydantic_ai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools

from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.utils import capture_internal_exceptions
from sentry_sdk.utils import capture_internal_exceptions, package_version

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

View check run for this annotation

@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.

try:
import pydantic_ai # type: ignore # noqa: F401
Expand Down Expand Up @@ -164,9 +164,17 @@
Hooks = None
PydanticAIIntegration.are_request_hooks_available = False

if Hooks is None:
# ModelRequestContext.model added in https://github.com/pydantic/pydantic-ai/commit/f1260dfe09907f17688eee1646daf898fc428d4c
PYDANTIC_AI_VERSION = package_version("pydantic-ai")
if PYDANTIC_AI_VERSION is not None and PYDANTIC_AI_VERSION < (
1,
73,
):
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Comment thread
cursor[bot] marked this conversation as resolved.
_patch_graph_nodes()

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

View check run for this annotation

@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.
return

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

View check run for this annotation

@sentry/warden / warden: code-review

Version guard bypassed when `package_version` returns `None`, re-exposing the AttributeError

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.
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Outdated
if Hooks is None:
return
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Outdated

hooks = Hooks()
register_hooks(hooks)
Loading