Skip to content

fix: make ResponseFunctionWebSearch.action optional to handle null API responses#3449

Open
C1-BA-B1-F3 wants to merge 2 commits into
openai:mainfrom
C1-BA-B1-F3:fix/response-function-web-search-action-optional
Open

fix: make ResponseFunctionWebSearch.action optional to handle null API responses#3449
C1-BA-B1-F3 wants to merge 2 commits into
openai:mainfrom
C1-BA-B1-F3:fix/response-function-web-search-action-optional

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Problem

The field is typed as (required), but the API can return for this field in some cases. This causes when users try to access without null-checking first.

Related issue: #3179

Root Cause

When the API returns a web search call with (e.g., when the search is still in progress or the action hasn't been determined yet), the SDK crashes because the type definition doesn't allow values.

Fix

Changed to in , matching the actual API behavior.

Testing

Added comprehensive tests covering:

  • Web search calls with search/open_page/find_in_page actions
  • Web search calls with (the bug case)
  • Web search calls without action field (defaults to None)
  • Safe access pattern for checking action type

All tests pass.

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
…I responses

Fixes openai#3179

The API can return null for the action field in web search calls (e.g.,
when the search is still in progress or the action hasn't been
determined yet). This change makes the action field Optional[Action]
with a default of None, matching the actual API behavior.

This allows users to safely check action.type without getting an
AttributeError when action is None.
@C1-BA-B1-F3 C1-BA-B1-F3 requested a review from a team as a code owner June 26, 2026 00:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54fafb3494

ℹ️ 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".

@@ -0,0 +1,133 @@
# Tests for ResponseFunctionWebSearch type
# Verifies that the action field correctly handles None values from the API
import pytest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fix new test imports to satisfy ruff

The repo's ruff check . gate fails on this new file: ruff check tests/test_response_function_web_search.py reports I001 for the import block and F401 because pytest is imported but unused. Remove the unused import and let ruff/isort reorder the remaining imports so CI can pass.

Useful? React with 👍 / 👎.

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.

1 participant