agentops icon indicating copy to clipboard operation
agentops copied to clipboard

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

Open guoyangzhen opened this issue 8 months ago • 0 comments

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__

guoyangzhen avatar Mar 20 '26 15:03 guoyangzhen