Skip to content

fix: add None checks before accessing __dict__ on optional tool fields#1305

Open
guoyangzhen wants to merge 1 commit intoAgentOps-AI:mainfrom
guoyangzhen:fix/none-check-tool-fields
Open

fix: add None checks before accessing __dict__ on optional tool fields#1305
guoyangzhen wants to merge 1 commit intoAgentOps-AI:mainfrom
guoyangzhen:fix/none-check-tool-fields

Conversation

@guoyangzhen
Copy link

Problem

When using OpenAI Agents SDK with file search or web search tools, on_span_end raises:

AttributeError: NoneType object has no attribute __dict__

The root cause: hasattr() returns True even when the attribute exists but is None. Then accessing .dict on None crashes.

Affected locations in response.py:

  • tool.user_location.dict (line ~506)
  • tool.filters.dict (line ~524)
  • tool.ranking_options.dict (line ~530)

Fix

Add is not None checks alongside hasattr():

# Before
if hasattr(tool, "user_location"):    parameters["user_location"] = tool.user_location.__dict__
# After
if hasattr(tool, "user_location") and tool.user_location is not None:
    parameters["user_location"] = tool.user_location.__dict__

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