Skip to content
Open
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def model_dump(
exclude_defaults=exclude_defaults,
# warnings are not supported in Pydantic v1
warnings=True if PYDANTIC_V1 else warnings,
by_alias=by_alias,
# pydantic-core's Rust serializer rejects None for by_alias; coerce to bool.
by_alias=bool(by_alias) if by_alias is not None else False,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve config-driven alias behavior in model_dump

When by_alias is omitted, supported Pydantic 2.11+ models can still serialize aliases via ConfigDict(serialize_by_alias=True). Forcing None to False here changes that contract: _compat.model_dump() no longer defers to the model config, and both _utils._transform._transform_recursive() and _async_transform_recursive() call this helper for arbitrary pydantic.BaseModel inputs when building request bodies. In that scenario, aliased third-party Pydantic models will now emit field names instead of aliases, which can send the wrong keys to the API.

Useful? React with 👍 / 👎.

)
return cast(
"dict[str, Any]",
Expand Down