Fix: crash of workflow file upload (#10831)
Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
@@ -27,8 +27,8 @@ NEW_VERSION_WORKFLOW_FEATURES = {
|
||||
"file_upload": {
|
||||
"enabled": True,
|
||||
"allowed_file_types": ["image"],
|
||||
"allowed_extensions": [],
|
||||
"allowed_upload_methods": ["remote_url", "local_file"],
|
||||
"allowed_file_extensions": [],
|
||||
"allowed_file_upload_methods": ["remote_url", "local_file"],
|
||||
"number_limits": 6,
|
||||
},
|
||||
"opening_statement": "",
|
||||
|
@@ -1,4 +1,7 @@
|
||||
from core.file import FILE_MODEL_IDENTITY, File, FileTransferMethod, FileType
|
||||
import json
|
||||
|
||||
from core.file import FILE_MODEL_IDENTITY, File, FileTransferMethod, FileType, FileUploadConfig
|
||||
from models.workflow import Workflow
|
||||
|
||||
|
||||
def test_file_loads_and_dumps():
|
||||
@@ -38,3 +41,40 @@ def test_file_to_dict():
|
||||
file_dict = file.to_dict()
|
||||
assert "_extra_config" not in file_dict
|
||||
assert "url" in file_dict
|
||||
|
||||
|
||||
def test_workflow_features_with_image():
|
||||
# Create a feature dict that mimics the old structure with image config
|
||||
features = {
|
||||
"file_upload": {
|
||||
"image": {"enabled": True, "number_limits": 5, "transfer_methods": ["remote_url", "local_file"]}
|
||||
}
|
||||
}
|
||||
|
||||
# Create a workflow instance with the features
|
||||
workflow = Workflow(
|
||||
tenant_id="tenant-1",
|
||||
app_id="app-1",
|
||||
type="chat",
|
||||
version="1.0",
|
||||
graph="{}",
|
||||
features=json.dumps(features),
|
||||
created_by="user-1",
|
||||
environment_variables=[],
|
||||
conversation_variables=[],
|
||||
)
|
||||
|
||||
# Get the converted features through the property
|
||||
converted_features = json.loads(workflow.features)
|
||||
|
||||
# Create FileUploadConfig from the converted features
|
||||
file_upload_config = FileUploadConfig.model_validate(converted_features["file_upload"])
|
||||
|
||||
# Validate the config
|
||||
assert file_upload_config.number_limits == 5
|
||||
assert list(file_upload_config.allowed_file_types) == [FileType.IMAGE]
|
||||
assert list(file_upload_config.allowed_file_upload_methods) == [
|
||||
FileTransferMethod.REMOTE_URL,
|
||||
FileTransferMethod.LOCAL_FILE,
|
||||
]
|
||||
assert list(file_upload_config.allowed_file_extensions) == []
|
||||
|
Reference in New Issue
Block a user