Skip to content

fix: coercing by_alias to bool#2922

Open
jasiecky wants to merge 1 commit intoopenai:mainfrom
jasiecky:fix/2921
Open

fix: coercing by_alias to bool#2922
jasiecky wants to merge 1 commit intoopenai:mainfrom
jasiecky:fix/2921

Conversation

@jasiecky
Copy link

@jasiecky jasiecky commented Mar 3, 2026

Fixes #2921

Added coercing by_alias to bool in openai/_compat.py so it's compatible with Pydantic v2.

@jasiecky jasiecky requested a review from a team as a code owner March 3, 2026 14:02
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6ef7db566

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# 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?

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.

Bug: by_alias: NoneType in openai-python v2.24.0 when logging.DEBUG is enabled

1 participant