fix(chatcmpl): handle reasoning items with provider_data=None#3301
fix(chatcmpl): handle reasoning items with provider_data=None#3301Quratulain-bilal wants to merge 4 commits intoopenai:mainfrom
Conversation
Converter.items_to_messages assumed reasoning_item["provider_data"] was
always either absent or a dict, calling .get("model", "") directly on the
result of reasoning_item.get("provider_data", {}). When the field is
explicitly set to None — which is preserved through JSON round-trips and
common from external producers/storage — this raised
AttributeError: 'NoneType' object has no attribute 'get' before any
reasoning content could be processed, breaking conversion entirely.
Treat any non-dict provider_data (None, list, scalar) as missing, which
matches the existing "ignore the check when provider_data is empty"
fallback already used a few lines below.
seratch
left a comment
There was a problem hiding this comment.
Can you resolve the CI error first?
The previous test built a TResponseInputItem and then assigned to item['provider_data'], which mypy rejected because every TypedDict in the TResponseInputItem union without a 'provider_data' key produced a typeddict-unknown-key error (58 in total). Build the input as a plain dict[str, Any] and cast at the call site so mypy only sees the cast, not the assignment. No runtime behavior change.
|
Thanks for the fix. I can see that this prevents Could you share the concrete path where this shape is produced in normal SDK usage? From a quick look, the SDK-owned Chat Completions / LiteLLM / Any-LLM conversion paths seem to either attach a non-empty dict or omit If this came from an actual user report or reproducible flow, it would be helpful to capture that in the test or PR description. |
|
You're right thanks for pushing on this. I can't point to a concrete SDK-owned flow that produces provider_data: |
Converter.items_to_messages assumed reasoning_item["provider_data"] was always either absent or a dict, calling .get("model", "") directly on the result of reasoning_item.get("provider_data", {}). When the field is explicitly set to None which is preserved through JSON round-trips and common from external producers/storage this raised AttributeError: 'NoneType' object has no attribute 'get' before any reasoning content could be processed, breaking conversion entirely.
Treat any non-dict provider_data (None, list, scalar) as missing, which matches the existing "ignore the check when provider_data is empty" fallback already used a few lines below.