Skip to content

fix: handle bare dict annotations in construct_type - #3386

Closed
Resurgamz wants to merge 1 commit into
openai:mainfrom
Resurgamz:fix/issue-3341-bare-dict-construct-type
Closed

fix: handle bare dict annotations in construct_type#3386
Resurgamz wants to merge 1 commit into
openai:mainfrom
Resurgamz:fix/issue-3341-bare-dict-construct-type

Conversation

@Resurgamz

Copy link
Copy Markdown

Summary

  • Return bare dict values unchanged during model construction when no value type argument is available.
  • Add a regression test for BaseModel.construct() with a field annotated as plain dict.

Changes

File Change
src/openai/_models.py Guard dict value type unpacking when get_args(dict) is empty.
tests/test_models.py Cover model construction for bare dict fields.

Test Plan

  • PYTHONPATH="$PWD/src" /home/ut006460@uos/project/openai-python/.venv/bin/python -m pytest tests/test_models.py -k bare_dictionary -n 0
  • PYTHONPATH="$PWD/src" /home/ut006460@uos/project/openai-python/.venv/bin/python -m pytest tests/test_models.py -n 0
  • /home/ut006460@uos/project/openai-python/.venv/bin/ruff format tests/test_models.py src/openai/_models.py
  • /home/ut006460@uos/project/openai-python/.venv/bin/ruff check tests/test_models.py src/openai/_models.py

Fixes #3341

Avoid unpacking missing type arguments when model construction sees an unparameterized dict field.

Fixes openai#3341
@Resurgamz
Resurgamz marked this pull request as ready for review June 9, 2026 01:43
@Resurgamz
Resurgamz requested a review from a team as a code owner June 9, 2026 01:43
@Resurgamz

Copy link
Copy Markdown
Author

@openai/sdks-team @apcha-oai Could you please help review and approve this PR? Thanks.

@Resurgamz

Copy link
Copy Markdown
Author

@apcha-oai Friendly follow-up: could you please help review this PR when you have a chance? Thanks.

Copy link
Copy Markdown
Contributor

Thank you for the contribution. The missing type arguments for bare dict annotations are now handled in model construction 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

Development

Successfully merging this pull request may close these issues.

BUG: construct_type() crashes with ValueError on bare dict annotation (no type args)

2 participants