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
2 changes: 1 addition & 1 deletion src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ 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,
by_alias=bool(by_alias),

Choose a reason for hiding this comment

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

P2 Badge Preserve None semantics for by_alias

In Pydantic v2, passing by_alias=None to model_dump() means “use the model config default” (e.g., serialize_by_alias=True), but coercing with bool(by_alias) turns None into False and unconditionally disables alias serialization. This changes output keys for models that rely on config-driven alias behavior whenever callers omit by_alias (or pass None), so the compatibility helper no longer matches native v2 behavior.

Useful? React with 👍 / 👎.

Copy link
Author

Choose a reason for hiding this comment

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

So should I add a condition that sets it to True if by_alias is None?

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