Fix AttributeError on None tool attributes in response#1286
Open
md-armaan13 wants to merge 1 commit intoAgentOps-AI:mainfrom
Open
Fix AttributeError on None tool attributes in response#1286md-armaan13 wants to merge 1 commit intoAgentOps-AI:mainfrom
md-armaan13 wants to merge 1 commit intoAgentOps-AI:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
is not Nonechecks foruser_location,filters, andranking_optionsbefore accessing
__dict__, preventing crash when these optional fieldsdefault to
None.Fixes #1285
📥 Pull Request
📘 Description
When using the OpenAI Agents SDK with file search or web search tools, the
on_span_endmethod crashes withAttributeError: 'NoneType' object has no attribute '__dict__'. This happens becauseuser_location,filters, andranking_optionsareoptional fields that default to
Nonein the OpenAI SDK, but the code only checkshasattr()(which returnsTrueeven whenthe value is
None) before calling.__dict__.This PR adds
is not Noneguards to all three locations inresponse.py:get_response_tool_web_search_attributes:tool.user_locationget_response_tool_file_search_attributes:tool.filtersandtool.ranking_options🧪 Testing
Added two new unit tests:
test_get_response_tool_web_search_attributes_none_user_location— verifiesuser_location=Noneis handled gracefullytest_get_response_tool_file_search_attributes_none_filters_and_ranking— verifiesfilters=Noneandranking_options=Noneare handled gracefully
All 15 tests in
test_response_attributes.pypass.