Skip to content

Fix AttributeError on None tool attributes in response#1286

Open
md-armaan13 wants to merge 1 commit intoAgentOps-AI:mainfrom
md-armaan13:openai-sdk/fix/response-tool-none-dict-crash
Open

Fix AttributeError on None tool attributes in response#1286
md-armaan13 wants to merge 1 commit intoAgentOps-AI:mainfrom
md-armaan13:openai-sdk/fix/response-tool-none-dict-crash

Conversation

@md-armaan13
Copy link

Add is not None checks for user_location, filters, and ranking_options
before accessing __dict__, preventing crash when these optional fields
default to None.

Fixes #1285

📥 Pull Request

📘 Description
When using the OpenAI Agents SDK with file search or web search tools, the on_span_end method crashes with AttributeError: 'NoneType' object has no attribute '__dict__'. This happens because user_location, filters, and ranking_options are
optional fields that default to None in the OpenAI SDK, but the code only checks hasattr() (which returns True even when
the value is None) before calling .__dict__.

This PR adds is not None guards to all three locations in response.py:

  • get_response_tool_web_search_attributes: tool.user_location
  • get_response_tool_file_search_attributes: tool.filters and tool.ranking_options

🧪 Testing
Added two new unit tests:

  • test_get_response_tool_web_search_attributes_none_user_location — verifies user_location=None is handled gracefully
  • test_get_response_tool_file_search_attributes_none_filters_and_ranking — verifies filters=None and ranking_options=None
    are handled gracefully

All 15 tests in test_response_attributes.py pass.

  Add 'is not None' checks for user_location, filters, and ranking_options
  before accessing __dict__, preventing crash when these optional fields
  default to None.

  Fixes AgentOps-AI#1285
@md-armaan13 md-armaan13 marked this pull request as draft March 6, 2026 13:59
@md-armaan13 md-armaan13 marked this pull request as ready for review March 6, 2026 13:59
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]: AttributeError: 'NoneType' object has no attribute '__dict__' in get_response_tool_web/file_search_attributes

1 participant