mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
fix(api): replace assert isinstance with proper runtime type checks in message transformers (#34865)
This commit is contained in:
parent
86fd94767c
commit
d19f47b458
@ -71,8 +71,8 @@ class DatasourceFileMessageTransformer:
|
|||||||
if not isinstance(message.message, DatasourceMessage.BlobMessage):
|
if not isinstance(message.message, DatasourceMessage.BlobMessage):
|
||||||
raise ValueError("unexpected message type")
|
raise ValueError("unexpected message type")
|
||||||
|
|
||||||
# FIXME: should do a type check here.
|
if not isinstance(message.message.blob, bytes):
|
||||||
assert 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_manager = ToolFileManager()
|
||||||
blob_tool_file: ToolFile | None = tool_file_manager.create_file_by_raw(
|
blob_tool_file: ToolFile | None = tool_file_manager.create_file_by_raw(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
|
|||||||
@ -118,7 +118,8 @@ class ToolFileMessageTransformer:
|
|||||||
if not isinstance(message.message, ToolInvokeMessage.BlobMessage):
|
if not isinstance(message.message, ToolInvokeMessage.BlobMessage):
|
||||||
raise ValueError("unexpected message type")
|
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_manager = ToolFileManager()
|
||||||
tool_file = tool_file_manager.create_file_by_raw(
|
tool_file = tool_file_manager.create_file_by_raw(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user