Skip to content

fix: handle bare dict/list annotations in construct_type and transform - #3447

Closed
C1-BA-B1-F3 wants to merge 1 commit into
openai:mainfrom
C1-BA-B1-F3:fix/bare-dict-list-annotations
Closed

fix: handle bare dict/list annotations in construct_type and transform#3447
C1-BA-B1-F3 wants to merge 1 commit into
openai:mainfrom
C1-BA-B1-F3:fix/bare-dict-list-annotations

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Problem

Using bare or annotations (without type parameters) crashes the SDK:

  • raises
  • raises
  • raises

This affects users who annotate fields as plain or instead of or .

Fixes #3338
Fixes #3341

Root Cause

The code unconditionally unpacks type args without checking if they exist:

  • line 660: — crashes on bare
  • line 681: — crashes on bare
  • line 183: — crashes on bare

Fix

Guard the type args access:

  • For : check before unpacking
  • For : check before accessing
  • When type args are missing, return the data as-is (graceful fallback)

Testing

Added 6 new tests covering bare dict/list in both and (sync + async). All 120 tests pass (114 existing + 6 new).

Guard against empty type args when using bare dict or list annotations
(no type parameters, e.g.  instead of ).

Previously:
- construct_type() raised ValueError on bare dict
- construct_type() raised IndexError on bare list
- _transform_recursive() raised IndexError on bare dict

Now these cases gracefully return the data as-is, matching the behavior
of parameterized types when the data already matches.

Fixes openai#3338, openai#3341
@C1-BA-B1-F3
C1-BA-B1-F3 requested a review from a team as a code owner June 25, 2026 23:57

Copy link
Copy Markdown
Contributor

Thank you for the contribution. The missing type arguments for bare dict and list annotations are now handled in model construction and sync/async request transformation by #3760, which is merged into main.

Closing this PR because the merged change resolves the same crash. Please use a release containing #3760 when available; the fix is not included in v3.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants