From a9a913dcfbb97d5cc034df5b88676f645395d825 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Mar 2026 22:25:50 +0000 Subject: [PATCH] fix: add None checks before accessing __dict__ on optional tool fields WebSearchTool.user_location, FileSearchTool.filters, and FileSearchTool.ranking_options are optional fields that default to None. The existing hasattr() guards return True even when the value is None, causing AttributeError: 'NoneType' object has no attribute '__dict__'. Fixes #1285 https://claude.ai/code/session_011TWMvnjeLgAJg9XtxoLfZT --- .../instrumentation/providers/openai/attributes/response.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agentops/instrumentation/providers/openai/attributes/response.py b/agentops/instrumentation/providers/openai/attributes/response.py index 195eb5bdb..9cf8f4b80 100644 --- a/agentops/instrumentation/providers/openai/attributes/response.py +++ b/agentops/instrumentation/providers/openai/attributes/response.py @@ -503,7 +503,7 @@ def get_response_tool_web_search_attributes(tool: "WebSearchTool", index: int) - if hasattr(tool, "search_context_size"): parameters["search_context_size"] = tool.search_context_size - if hasattr(tool, "user_location"): + if hasattr(tool, "user_location") and tool.user_location is not None: parameters["user_location"] = tool.user_location.__dict__ tool_data = tool.__dict__ @@ -521,13 +521,13 @@ def get_response_tool_file_search_attributes(tool: "FileSearchTool", index: int) if hasattr(tool, "vector_store_ids"): parameters["vector_store_ids"] = tool.vector_store_ids - if hasattr(tool, "filters"): + if hasattr(tool, "filters") and tool.filters is not None: parameters["filters"] = tool.filters.__dict__ if hasattr(tool, "max_num_results"): parameters["max_num_results"] = tool.max_num_results - if hasattr(tool, "ranking_options"): + if hasattr(tool, "ranking_options") and tool.ranking_options is not None: parameters["ranking_options"] = tool.ranking_options.__dict__ tool_data = tool.__dict__