fix: improve error handling in valid_reference_value function
This commit is contained in:
parent
7ec7984b9f
commit
bf1062ff04
@ -20,8 +20,6 @@ from common.exception.app_exception import AppApiException
|
|||||||
from common.utils.rsa_util import rsa_long_decrypt
|
from common.utils.rsa_util import rsa_long_decrypt
|
||||||
from common.utils.tool_code import ToolExecutor
|
from common.utils.tool_code import ToolExecutor
|
||||||
from maxkb.const import CONFIG
|
from maxkb.const import CONFIG
|
||||||
from system_manage.models import AuthTargetType
|
|
||||||
from system_manage.serializers.user_resource_permission import UserResourcePermissionSerializer
|
|
||||||
from tools.models import Tool
|
from tools.models import Tool
|
||||||
|
|
||||||
function_executor = ToolExecutor(CONFIG.get('SANDBOX'))
|
function_executor = ToolExecutor(CONFIG.get('SANDBOX'))
|
||||||
@ -48,23 +46,30 @@ def get_field_value(debug_field_list, name, is_required):
|
|||||||
|
|
||||||
|
|
||||||
def valid_reference_value(_type, value, name):
|
def valid_reference_value(_type, value, name):
|
||||||
if _type == 'int':
|
try:
|
||||||
instance_type = int | float
|
if _type == 'int':
|
||||||
elif _type == 'float':
|
instance_type = int | float
|
||||||
instance_type = float | int
|
elif _type == 'float':
|
||||||
elif _type == 'dict':
|
instance_type = float | int
|
||||||
instance_type = dict
|
elif _type == 'dict':
|
||||||
elif _type == 'array':
|
value = json.loads(value) if isinstance(value, str) else value
|
||||||
instance_type = list
|
instance_type = dict
|
||||||
elif _type == 'string':
|
elif _type == 'array':
|
||||||
instance_type = str
|
value = json.loads(value) if isinstance(value, str) else value
|
||||||
else:
|
instance_type = list
|
||||||
raise Exception(_('Field: {name} Type: {_type} Value: {value} Unsupported types').format(name=name,
|
elif _type == 'string':
|
||||||
_type=_type))
|
instance_type = str
|
||||||
|
else:
|
||||||
|
raise Exception(_(
|
||||||
|
'Field: {name} Type: {_type} Value: {value} Unsupported types'
|
||||||
|
).format(name=name, _type=_type))
|
||||||
|
except:
|
||||||
|
return value
|
||||||
if not isinstance(value, instance_type):
|
if not isinstance(value, instance_type):
|
||||||
raise Exception(
|
raise Exception(_(
|
||||||
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
|
'Field: {name} Type: {_type} Value: {value} Type error'
|
||||||
value=value))
|
).format(name=name, _type=_type, value=value))
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def convert_value(name: str, value, _type, is_required, source, node):
|
def convert_value(name: str, value, _type, is_required, source, node):
|
||||||
@ -76,12 +81,8 @@ def convert_value(name: str, value, _type, is_required, source, node):
|
|||||||
value = node.workflow_manage.get_reference_field(
|
value = node.workflow_manage.get_reference_field(
|
||||||
value[0],
|
value[0],
|
||||||
value[1:])
|
value[1:])
|
||||||
if isinstance(value, str):
|
|
||||||
try:
|
value = valid_reference_value(_type, value, name)
|
||||||
value = json.loads(value)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
valid_reference_value(_type, value, name)
|
|
||||||
if _type == 'int':
|
if _type == 'int':
|
||||||
return int(value)
|
return int(value)
|
||||||
if _type == 'float':
|
if _type == 'float':
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import json
|
|||||||
import time
|
import time
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from application.flow.i_step_node import NodeResult
|
from application.flow.i_step_node import NodeResult
|
||||||
from application.flow.step_node.tool_node.i_tool_node import IToolNode
|
from application.flow.step_node.tool_node.i_tool_node import IToolNode
|
||||||
from common.utils.tool_code import ToolExecutor
|
from common.utils.tool_code import ToolExecutor
|
||||||
@ -30,20 +32,30 @@ def write_context(step_variable: Dict, global_variable: Dict, node, workflow):
|
|||||||
|
|
||||||
|
|
||||||
def valid_reference_value(_type, value, name):
|
def valid_reference_value(_type, value, name):
|
||||||
if _type == 'int':
|
try:
|
||||||
instance_type = int | float
|
if _type == 'int':
|
||||||
elif _type == 'float':
|
instance_type = int | float
|
||||||
instance_type = float | int
|
elif _type == 'float':
|
||||||
elif _type == 'dict':
|
instance_type = float | int
|
||||||
instance_type = dict
|
elif _type == 'dict':
|
||||||
elif _type == 'array':
|
value = json.loads(value) if isinstance(value, str) else value
|
||||||
instance_type = list
|
instance_type = dict
|
||||||
elif _type == 'string':
|
elif _type == 'array':
|
||||||
instance_type = str
|
value = json.loads(value) if isinstance(value, str) else value
|
||||||
else:
|
instance_type = list
|
||||||
raise Exception(500, f'字段:{name}类型:{_type} 不支持的类型')
|
elif _type == 'string':
|
||||||
|
instance_type = str
|
||||||
|
else:
|
||||||
|
raise Exception(_(
|
||||||
|
'Field: {name} Type: {_type} Value: {value} Unsupported types'
|
||||||
|
).format(name=name, _type=_type))
|
||||||
|
except:
|
||||||
|
return value
|
||||||
if not isinstance(value, instance_type):
|
if not isinstance(value, instance_type):
|
||||||
raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误')
|
raise Exception(_(
|
||||||
|
'Field: {name} Type: {_type} Value: {value} Type error'
|
||||||
|
).format(name=name, _type=_type, value=value))
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def convert_value(name: str, value, _type, is_required, source, node):
|
def convert_value(name: str, value, _type, is_required, source, node):
|
||||||
@ -53,12 +65,8 @@ def convert_value(name: str, value, _type, is_required, source, node):
|
|||||||
value = node.workflow_manage.get_reference_field(
|
value = node.workflow_manage.get_reference_field(
|
||||||
value[0],
|
value[0],
|
||||||
value[1:])
|
value[1:])
|
||||||
if isinstance(value, str):
|
|
||||||
try:
|
value = valid_reference_value(_type, value, name)
|
||||||
value = json.loads(value)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
valid_reference_value(_type, value, name)
|
|
||||||
if _type == 'int':
|
if _type == 'int':
|
||||||
return int(value)
|
return int(value)
|
||||||
if _type == 'float':
|
if _type == 'float':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user