Skip to content

fix: convert by_alias=None to bool for pydantic v2#2967

Open
Jah-yee wants to merge 1 commit intoopenai:mainfrom
Jah-yee:fix/by-alias-none-pydantic-v2
Open

fix: convert by_alias=None to bool for pydantic v2#2967
Jah-yee wants to merge 1 commit intoopenai:mainfrom
Jah-yee:fix/by-alias-none-pydantic-v2

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 13, 2026

When DEBUG logging is enabled, model_dump() is called with by_alias=None (the default), which causes pydantic-core Rust serializer to raise:

TypeError: argument by_alias: NoneType object cannot be converted to PyBool

This fix converts None to True (pydantic default behavior) before passing to model_dump() for pydantic v2.

Root cause: The _compat.py function signature declares by_alias: bool | None = None, but passes it directly to pydantic v2s model_dump() which expects a bool, not None.

Fix: Convert by_alias to bool when passing to pydantic v2, defaulting to True (pydantic default) when None is passed.

Fixes: #2965

When DEBUG logging is enabled, model_dump() is called with by_alias=None
(the default), which causes pydantic-core's Rust serializer to raise:
TypeError: argument 'by_alias': 'NoneType' object cannot be converted to 'PyBool'

This fix converts None to True (pydantic's default behavior) when passing
to model_dump() for pydantic v2.

Fixes: openai#2965
@Jah-yee Jah-yee requested a review from a team as a code owner March 13, 2026 07:10
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.

1 participant