From 838aa742cb790da6a99a3399bf805d725ca1a726 Mon Sep 17 00:00:00 2001 From: AlexFucuson9 Date: Wed, 1 Jul 2026 08:20:14 +0700 Subject: [PATCH] fix(agent): guard .get(key, "").method() None dereference in adapters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dict.get(key, default) returns None (not the default) when the key EXISTS with value None. The default only applies when the key is ABSENT. Chained method calls (.strip(), .upper(), .count()) crash with AttributeError on NoneType. Fix two confirmed hits: - auxiliary_client.py: custom provider base_url/api_key (config null) - anthropic_adapter.py: text block content (API null response) Pattern: .get(key, "").method() → (.get(key) or "").method() --- agent/anthropic_adapter.py | 2 +- agent/auxiliary_client.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.py index 623560250df4..215868306348 100644 --- a/agent/anthropic_adapter.py +++ b/agent/anthropic_adapter.py @@ -2102,7 +2102,7 @@ def _convert_user_message(content: Any) -> Dict[str, Any]: if isinstance(content, list): converted_blocks = _convert_content_to_anthropic(content) if not converted_blocks or all( - b.get("text", "").strip() == "" + (b.get("text") or "").strip() == "" for b in converted_blocks if isinstance(b, dict) and b.get("type") == "text" ): diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index b1d9a8135e6f..d8ff9204daed 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -4716,8 +4716,8 @@ def resolve_provider_client( if custom_entry is None: custom_entry = _get_named_custom_provider(provider) if custom_entry: - custom_base = custom_entry.get("base_url", "").strip() - custom_key = custom_entry.get("api_key", "").strip() + custom_base = (custom_entry.get("base_url") or "").strip() + custom_key = (custom_entry.get("api_key") or "").strip() custom_key_env = (custom_entry.get("key_env") or custom_entry.get("api_key_env") or "").strip() if not custom_key and custom_key_env: custom_key = os.getenv(custom_key_env, "").strip()