fix: transform Omit values in pre-connect Realtime manager send()#3448
fix: transform Omit values in pre-connect Realtime manager send()#3448C1-BA-B1-F3 wants to merge 1 commit into
Conversation
The pre-connect send() methods on both AsyncRealtimeConnectionManager and RealtimeConnectionManager called json.dumps(event) directly on dict payloads, which crashed with TypeError when the event contained Omit values (e.g. event_id=omit). The connected send() methods already used maybe_transform() to strip Omit values before serialization. This commit applies the same transformation to the pre-connect send() methods for consistency. Fixes openai#3402
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1279b173be
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| """Pre-connect send() should strip all Omit values from dict events.""" | ||
| manager = _make_sync_manager() | ||
|
|
||
| event = {"type": "response.create", "event_id": omit, "response": {"modalities": omit}} |
There was a problem hiding this comment.
Fix nested omit test to use the typed field
This nested omit case still raises before the assertions because modalities is not a field in the current RealtimeResponseCreateParamsParam (the typed field is output_modalities), and _transform_typeddict preserves unknown keys instead of stripping their omit values. As written, maybe_transform leaves response.modalities = omit, so json.dumps(...) fails with TypeError and the new regression test suite fails; the async copy below has the same issue.
Useful? React with 👍 / 👎.
Fixes #3402.
Summary
The pre-connect
send()methods on bothAsyncRealtimeConnectionManagerandRealtimeConnectionManagercalledjson.dumps(event)directly on dict payloads, which crashed withTypeErrorwhen the event containedOmitvalues (e.g.event_id=omit).The connected
send()methods already usedmaybe_transform()to stripOmitvalues before serialization. This PR applies the same transformation to the pre-connectsend()methods for consistency.Changes
src/openai/resources/realtime/realtime.py: Updated both sync and async pre-connectsend()methods to usemaybe_transform(event, RealtimeClientEventParam)beforejson.dumps()tests/test_realtime_manager_send_omit.py: Added regression tests verifying:omitvalues are properly stripped before serializationomitvalues preserve all fieldsomitfields are all stripped correctlyReproduction
Before this fix:
After this fix, the
omitvalue is stripped and the event is serialized correctly.