From b28577bb03506866c105facae5824b03ef523d28 Mon Sep 17 00:00:00 2001 From: Jah-yee Date: Fri, 13 Mar 2026 15:09:28 +0800 Subject: [PATCH] fix: convert by_alias=None to bool for pydantic v2 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: #2965 --- src/openai/_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openai/_compat.py b/src/openai/_compat.py index 020ffeb2ca..778bca4d02 100644 --- a/src/openai/_compat.py +++ b/src/openai/_compat.py @@ -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) if by_alias is not None else True, ) return cast( "dict[str, Any]",