mirror of
https://github.com/langgenius/dify.git
synced 2026-06-03 08:16:37 +08:00
fix(api): replace assert isinstance with proper runtime type checks in message transformers (#34865)
This commit is contained in:
@@ -71,8 +71,8 @@ class DatasourceFileMessageTransformer:
|
||||
if not isinstance(message.message, DatasourceMessage.BlobMessage):
|
||||
raise ValueError("unexpected message type")
|
||||
|
||||
# FIXME: should do a type check here.
|
||||
assert isinstance(message.message.blob, bytes)
|
||||
if not isinstance(message.message.blob, bytes):
|
||||
raise TypeError(f"Expected blob to be bytes, got {type(message.message.blob).__name__}")
|
||||
tool_file_manager = ToolFileManager()
|
||||
blob_tool_file: ToolFile | None = tool_file_manager.create_file_by_raw(
|
||||
user_id=user_id,
|
||||
|
||||
@@ -118,7 +118,8 @@ class ToolFileMessageTransformer:
|
||||
if not isinstance(message.message, ToolInvokeMessage.BlobMessage):
|
||||
raise ValueError("unexpected message type")
|
||||
|
||||
assert isinstance(message.message.blob, bytes)
|
||||
if not isinstance(message.message.blob, bytes):
|
||||
raise TypeError(f"Expected blob to be bytes, got {type(message.message.blob).__name__}")
|
||||
tool_file_manager = ToolFileManager()
|
||||
tool_file = tool_file_manager.create_file_by_raw(
|
||||
user_id=user_id,
|
||||
|
||||
Reference in New Issue
Block a user