fix: handle bare dict annotations in construct_type#3379
fix: handle bare dict annotations in construct_type#3379Muhtasim-Munif-Fahim wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves model/type handling and schema parity by ensuring realtime error payloads include a human-readable message, and by making construct_type() safely handle bare dict annotations.
Changes:
- Add
messagefield toRealtimeResponseStatus.Error(beta and non-beta). - Update
construct_type()to toleratetype_=dict(no generic args) without throwing. - Add tests for bare
dictannotation and for realtime errormessageparsing.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_models.py | Adds regression test for construct_type(..., type_=dict) behavior |
| tests/lib/test_realtime_response_status.py | Adds test asserting realtime status error payload includes message in both beta and stable types |
| src/openai/types/realtime/realtime_response_status.py | Adds Error.message field to realtime status model |
| src/openai/types/beta/realtime/realtime_response_status.py | Adds Error.message field to beta realtime status model |
| src/openai/_models.py | Fixes construct_type() dict handling when dict is not subscripted |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| args = get_args(type_) | ||
| if len(args) < 2: | ||
| return value | ||
| items_type = args[1] | ||
| return {key: construct_type(value=item, type_=items_type) for key, item in value.items()} |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa64636434
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ids=["beta", "realtime"], | ||
| ) | ||
| def test_realtime_response_status_error_message(status_cls: type[BaseModel]) -> None: | ||
| status = status_cls.model_validate( |
There was a problem hiding this comment.
Use a Pydantic-v1-compatible model constructor
The repository supports Pydantic 1.x, and the test-pydantic-v1 nox session runs this test without excluding it, but Pydantic v1's BaseModel has no model_validate method and the SDK does not provide that shim. This therefore raises AttributeError for both parametrized cases in the compatibility suite; construct the models through a version-compatible helper such as parse_obj instead.
Useful? React with 👍 / 👎.
Fix
construct_type()so a baredictannotation does not crash when the code path inspectsget_args(type_).This keeps the deserialization path aligned with the transform utility and preserves the input value unchanged when there are no dict type arguments.
Tests:
python -m pytest tests/test_models.py -k "bare_dict_annotation or extra_properties" -qpython -m py_compile src/openai/_models.py tests/test_models.py