Skip to content

chore(openai-agents): Use model_dump() instead of deprecated dict() - #7862

Merged
alexander-alderman-webb merged 4 commits into
getsentry:masterfrom
intertermux-code:fix/7827-pydantic-deprecated
Oct 5, 2026
Merged

alexander-alderman-webb merged 4 commits into
getsentry:masterfrom
intertermux-code:fix/7827-pydantic-deprecated

Conversation

@intertermux-code

Copy link
Copy Markdown
Contributor

Resubmitting as a single-change PR per your feedback on #7857.

Description

_set_output_data in the OpenAI Agents integration (and _set_common_output_data in the OpenAI integration's Responses API path) serialized pydantic models with the v1 .dict() API. On pydantic v2 that emits PydanticDeprecatedSince20, which breaks anyone running with DeprecationWarnings as errors.

Every supported openai/openai-agents version requires pydantic v2, so .model_dump() is a drop-in replacement. The OpenAI integration already calls .model_dump() unconditionally a few lines above (chat completions path), and the Anthropic/LiteLLM integrations use the same pattern.

Changed:

  • sentry_sdk/integrations/openai_agents/utils.py: 2 calls
  • sentry_sdk/integrations/openai.py: 4 calls (both record-outputs branches of the Responses API path)

Added test_set_output_data_tool_calls_no_pydantic_deprecation, which runs _set_output_data with a function call plus a message carrying non-text content (the refusal path) under warnings.simplefilter("error", DeprecationWarning).

Issues

Reminders

  • Please add tests to validate your changes, and lint your code using uv run ruff.
  • Add GH Issue ID & Linear ID (if applicable)
  • PR title should use conventional commit style (feat:, fix:, meta:)

…aths

The pydantic v1 .dict() API emits PydanticDeprecatedSince20 on
pydantic v2, which breaks anyone running with DeprecationWarnings as
errors. Every supported openai/openai-agents version requires
pydantic v2, so model_dump() is a drop-in replacement here.

Fixes getsentry#7827.
@intertermux-code
intertermux-code requested a review from a team as a code owner October 5, 2026 08:58
Comment thread tests/integrations/openai_agents/test_openai_agents.py Outdated
Maintainer feedback: the new test duplicates coverage already provided
by the existing suite, so it is not needed. The fix itself (model_dump()
instead of dict()) is unchanged.
@alexander-alderman-webb

Copy link
Copy Markdown
Contributor

This doesn't actually work because you can use openai-python with Pydantic v1, in which model_dump() is not available. See https://github.com/openai/openai-python/blob/becc1d20eed83c1b8d85e15dc131a372d9dc7813/pyproject.toml#L13.

I'm going to close this and write on the issue.

@alexander-alderman-webb

Copy link
Copy Markdown
Contributor

Or @intertermux-code feel free to apply the fix only for openai-agents.

openai-python supports Pydantic v1 (where model_dump() doesn't exist), so
revert the .dict() -> model_dump() change in the openai-python integration
and keep it only in sentry_sdk/integrations/openai_agents/utils.py, where
the openai-agents SDK guarantees Pydantic v2.

Also fold the test import back to a single line; the multi-line form was
only needed for the removed regression test's extra import.
@intertermux-code

Copy link
Copy Markdown
Contributor Author

Good catch — scoped it down to the openai-agents integration only and reverted the openai-python changes, since openai-python still supports Pydantic v1 where model_dump() doesn't exist. The openai-agents path keeps model_dump() (Pydantic v2 is guaranteed there).

Comment thread sentry_sdk/integrations/openai.py Outdated
Restores the original multi-line form around output_message.dict(); no
behavioral change. The model_dump() migration now applies only to the
openai-agents integration, per review.
@alexander-alderman-webb alexander-alderman-webb changed the title fix: use model_dump() instead of deprecated dict() in OpenAI output paths chore(openai-agents): Use model_dump() instead of deprecated dict() Oct 5, 2026
@alexander-alderman-webb
alexander-alderman-webb merged commit c5f80df into getsentry:master Oct 5, 2026
309 of 311 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI Agents integration emits PydanticDeprecatedSince20 on tool calls - _set_output_data calls dict()

2 participants