fix(compat): handle None by_alias in model_dump for Pydantic v2#2953
Open
mvanhorn wants to merge 1 commit intoopenai:mainfrom
Open
fix(compat): handle None by_alias in model_dump for Pydantic v2#2953mvanhorn wants to merge 1 commit intoopenai:mainfrom
mvanhorn wants to merge 1 commit intoopenai:mainfrom
Conversation
Pydantic v2's Rust serializer requires by_alias to be a bool, not None. The v1 fallback path already did bool(by_alias), but the v2 path passed None directly, causing TypeError when DEBUG logging was enabled. Fixes openai#2921 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2921
Problem
model_dump()in_compat.pypassesby_alias=Noneto Pydantic v2'smodel_dump(), which requires abool. The Rust serializer raises:This triggers when the
openailogger hasDEBUGlevel enabled, because the affectedmodel_dump()call is inside alog.isEnabledFor(logging.DEBUG)block.Fix
Convert
by_aliasfromNonetoFalsebefore passing to Pydantic v2'smodel_dump(), matching the pattern already used in the Pydantic v1 fallback path (line 157:by_alias=bool(by_alias)).Tests
Added
tests/compat/test_model_dump.pywith tests forby_alias=None,True, andFalse.This contribution was developed with AI assistance (Claude Code).