mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-21 07:55:08 +00:00
fix(dingtalk): broaden optional-SDK import guards to catch non-ImportError (cryptography version skew)
CI shard (test 1) deterministically failed importing the dingtalk plugin:
alibabacloud_dingtalk transitively imports cryptography and raises
AttributeError ('cryptography.utils' has no attribute 'DeprecatedIn46') when
CI's cryptography is older than the SDK expects. The adapter guarded that SDK
import with 'except ImportError', which does NOT catch AttributeError, so the
whole adapter (and thus plugin discovery via __init__'s 'from .adapter import
register') crashed instead of degrading. Broadened the alibabacloud_dingtalk
guard, the dingtalk_stream guard, and the check_dingtalk_requirements lazy
re-import to 'except Exception' so a broken optional SDK dependency chain
degrades gracefully (CARD_SDK_AVAILABLE/DINGTALK_STREAM_AVAILABLE=False), same
as a missing dep. This was invisible before migration because the inline
adapter was only imported when dingtalk was activated, not at plugin-discovery
time.
This commit is contained in:
parent
a51c7397b4
commit
d2ac38cf6c
1 changed files with 11 additions and 4 deletions
|
|
@ -42,7 +42,7 @@ try:
|
|||
from dingtalk_stream.frames import CallbackMessage, AckMessage
|
||||
|
||||
DINGTALK_STREAM_AVAILABLE = True
|
||||
except ImportError:
|
||||
except Exception: # noqa: BLE001 — broad: optional SDK's transitive deps (cryptography) may raise non-ImportError; degrade gracefully (#41112)
|
||||
DINGTALK_STREAM_AVAILABLE = False
|
||||
dingtalk_stream = None # type: ignore[assignment]
|
||||
ChatbotMessage = None # type: ignore[assignment]
|
||||
|
|
@ -64,7 +64,14 @@ except ImportError:
|
|||
HTTPX_AVAILABLE = False
|
||||
httpx = None # type: ignore[assignment]
|
||||
|
||||
# Card SDK for AI Cards (following QwenPaw pattern)
|
||||
# Card SDK for AI Cards (following QwenPaw pattern).
|
||||
# Catch broad Exception, not just ImportError: the alibabacloud_dingtalk SDK
|
||||
# transitively imports cryptography and can raise AttributeError (not
|
||||
# ImportError) when the installed cryptography version skews from what the SDK
|
||||
# expects (e.g. `cryptography.utils.DeprecatedIn46` missing on older
|
||||
# cryptography). An optional SDK with a broken dependency chain must degrade
|
||||
# gracefully — same as a missing one — rather than crash the whole adapter
|
||||
# (and therefore the whole plugin) import. #41112.
|
||||
try:
|
||||
from alibabacloud_dingtalk.card_1_0 import (
|
||||
client as dingtalk_card_client,
|
||||
|
|
@ -78,7 +85,7 @@ try:
|
|||
from alibabacloud_tea_util import models as tea_util_models
|
||||
|
||||
CARD_SDK_AVAILABLE = True
|
||||
except ImportError:
|
||||
except Exception:
|
||||
CARD_SDK_AVAILABLE = False
|
||||
dingtalk_card_client = None
|
||||
dingtalk_card_models = None
|
||||
|
|
@ -129,7 +136,7 @@ def check_dingtalk_requirements() -> bool:
|
|||
from dingtalk_stream import ChatbotMessage as _CM
|
||||
from dingtalk_stream.frames import CallbackMessage as _CBM, AckMessage as _AM
|
||||
import httpx as _httpx
|
||||
except ImportError:
|
||||
except Exception:
|
||||
return False
|
||||
dingtalk_stream = _ds
|
||||
ChatbotMessage = _CM
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue