diff --git a/apps/application/flow/step_node/tool_lib_node/impl/base_tool_lib_node.py b/apps/application/flow/step_node/tool_lib_node/impl/base_tool_lib_node.py index 0f8df18bc6a..3cd056b9534 100644 --- a/apps/application/flow/step_node/tool_lib_node/impl/base_tool_lib_node.py +++ b/apps/application/flow/step_node/tool_lib_node/impl/base_tool_lib_node.py @@ -58,26 +58,24 @@ def get_field_value(debug_field_list, name, is_required): def valid_reference_value(_type, value, name): - try: - if _type == 'int': - instance_type = int | float - elif _type == 'boolean': - instance_type = bool - elif _type == 'float': - instance_type = float | int - elif _type == 'dict': - value = json.loads(value) if isinstance(value, str) else value - instance_type = dict - elif _type == 'array': - value = json.loads(value) if isinstance(value, str) else value - instance_type = list - elif _type == 'string': - instance_type = str - else: - raise Exception(_( - 'Field: {name} Type: {_type} Value: {value} Unsupported types' - ).format(name=name, _type=_type, value=value)) - except: + if _type == 'int': + instance_type = int | float + elif _type == 'boolean': + instance_type = bool + elif _type == 'float': + instance_type = float | int + elif _type == 'dict': + value = json.loads(value) if isinstance(value, str) else value + instance_type = dict + elif _type == 'array': + value = json.loads(value) if isinstance(value, str) else value + instance_type = list + elif _type == 'string': + instance_type = str + else: + maxkb_logger.error(_( + 'Field: {name} Type: {_type} Value: {value} Unsupported this type' + ).format(name=name, _type=_type, value=value)) return value if not isinstance(value, instance_type): raise Exception(_( diff --git a/apps/application/flow/step_node/tool_node/impl/base_tool_node.py b/apps/application/flow/step_node/tool_node/impl/base_tool_node.py index f637abf0784..c5595bc805e 100644 --- a/apps/application/flow/step_node/tool_node/impl/base_tool_node.py +++ b/apps/application/flow/step_node/tool_node/impl/base_tool_node.py @@ -15,6 +15,7 @@ from application.flow.i_step_node import NodeResult from application.flow.step_node.tool_node.i_tool_node import IToolNode from common.utils.common import common_convert_value +from common.utils.logger import maxkb_logger from common.utils.tool_code import ToolExecutor from maxkb.const import CONFIG @@ -33,26 +34,24 @@ def write_context(step_variable: Dict, global_variable: Dict, node, workflow): def valid_reference_value(_type, value, name): - try: - if _type == 'int': - instance_type = int | float - elif _type == 'boolean': - instance_type = bool - elif _type == 'float': - instance_type = float | int - elif _type == 'dict': - value = json.loads(value) if isinstance(value, str) else value - instance_type = dict - elif _type == 'array': - value = json.loads(value) if isinstance(value, str) else value - instance_type = list - elif _type == 'string': - instance_type = str - else: - raise Exception(_( - 'Field: {name} Type: {_type} Value: {value} Unsupported types' - ).format(name=name, _type=_type, value=value)) - except: + if _type == 'int': + instance_type = int | float + elif _type == 'boolean': + instance_type = bool + elif _type == 'float': + instance_type = float | int + elif _type == 'dict': + value = json.loads(value) if isinstance(value, str) else value + instance_type = dict + elif _type == 'array': + value = json.loads(value) if isinstance(value, str) else value + instance_type = list + elif _type == 'string': + instance_type = str + else: + maxkb_logger.error(_( + 'Field: {name} Type: {_type} Value: {value} Unsupported this type' + ).format(name=name, _type=_type, value=value)) return value if not isinstance(value, instance_type): raise Exception(_( diff --git a/apps/locales/en_US/LC_MESSAGES/django.po b/apps/locales/en_US/LC_MESSAGES/django.po index 2bb6c26f686..1f2e7721527 100644 --- a/apps/locales/en_US/LC_MESSAGES/django.po +++ b/apps/locales/en_US/LC_MESSAGES/django.po @@ -595,7 +595,7 @@ msgstr "" #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:59 #, python-brace-format -msgid "Field: {name} Type: {_type} Value: {value} Unsupported types" +msgid "Field: {name} Type: {_type} Value: {value} Unsupported this type" msgstr "" #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:63 diff --git a/apps/locales/zh_CN/LC_MESSAGES/django.po b/apps/locales/zh_CN/LC_MESSAGES/django.po index 0670f7d7dce..9bafa2a542d 100644 --- a/apps/locales/zh_CN/LC_MESSAGES/django.po +++ b/apps/locales/zh_CN/LC_MESSAGES/django.po @@ -605,8 +605,8 @@ msgid "Field: {name} No value set" msgstr "字段:{name} 未设置值" #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:59 -msgid "Field: {name} Type: {_type} Value: {value} Unsupported types" -msgstr "字段:{name} 类型:{_type} 值:{value} 类型转换错误" +msgid "Field: {name} Type: {_type} Value: {value} Unsupported this type" +msgstr "字段:{name} 类型:{_type} 值:{value} 不支持该类型" #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:63 #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:100 diff --git a/apps/locales/zh_Hant/LC_MESSAGES/django.po b/apps/locales/zh_Hant/LC_MESSAGES/django.po index 3460c24c4d2..eb2cb07d85d 100644 --- a/apps/locales/zh_Hant/LC_MESSAGES/django.po +++ b/apps/locales/zh_Hant/LC_MESSAGES/django.po @@ -605,8 +605,8 @@ msgid "Field: {name} No value set" msgstr "欄位:{name} 未設置值" #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:59 -msgid "Field: {name} Type: {_type} Value: {value} Unsupported types" -msgstr "欄位:{name} 類型:{_type} 值:{value} 類型轉換錯誤" +msgid "Field: {name} Type: {_type} Value: {value} Unsupported this type" +msgstr "欄位:{name} 類型:{_type} 值:{value} 不支持該類型" #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:63 #: apps/application/flow/step_node/function_lib_node/impl/base_function_lib_node.py:100 diff --git a/apps/trigger/handler/impl/task/application_task.py b/apps/trigger/handler/impl/task/application_task.py index 1b6b200f592..16cfed8b49a 100644 --- a/apps/trigger/handler/impl/task/application_task.py +++ b/apps/trigger/handler/impl/task/application_task.py @@ -32,10 +32,10 @@ def get_reference(fields, obj): def conversion_custom_value(value, _type): - if ['array', 'dict', 'float', 'int', 'boolean', 'any'].__contains__(_type): + if _type in ('array', 'dict', 'float', 'int', 'boolean', 'any'): try: return json.loads(value) - except Exception as e: + except Exception: pass return value @@ -48,7 +48,7 @@ def valid_value_type(value, _type): if _type == 'float': return isinstance(value, float) if _type == 'int': - return isinstance(value, int) + return isinstance(value, int) and not isinstance(value, bool) if _type == 'boolean': return isinstance(value, bool) if _type == 'any': @@ -62,15 +62,17 @@ def get_field_value(value, kwargs, _type, required, default_value, field): _value = value.get('value') if _value: _value = conversion_custom_value(_value, _type) - else: - if default_value: - return default_value - if required: - raise Exception(f'{field} is required') - else: - return None else: _value = get_reference(value.get('value'), kwargs) + + if _value is None: + if default_value: + return default_value + if required: + raise Exception(f'{field} is required') + else: + return None + valid = valid_value_type(_value, _type) if not valid: raise Exception(f'{field} type error') diff --git a/apps/trigger/handler/impl/trigger/event_trigger.py b/apps/trigger/handler/impl/trigger/event_trigger.py index 6cc55702909..6ff6d7d5d94 100644 --- a/apps/trigger/handler/impl/trigger/event_trigger.py +++ b/apps/trigger/handler/impl/trigger/event_trigger.py @@ -19,6 +19,7 @@ from common.exception.app_exception import AppApiException, AppAuthenticationFailed from common.log.log import _get_ip_address from common.result import Result +from common.utils.logger import maxkb_logger from trigger.handler.base_trigger import BaseTrigger from trigger.models import TriggerTask, Trigger from trigger.serializers.trigger import TriggerResponse @@ -26,30 +27,27 @@ def valid_parameter_type(value, _type, desc): - try: - if _type == 'int': - instance_type = int | float - elif _type == 'boolean': - instance_type = bool - elif _type == 'float': - instance_type = float | int - elif _type == 'dict': - instance_type = dict - elif _type == 'array': - instance_type = list - elif _type == 'string': - instance_type = str - else: - raise Exception(_( - 'Field: {name} Type: {_type} Value: {value} Unsupported types' - ).format(name=desc, _type=_type, value=value)) - except: - return value + if _type == 'int': + instance_type = int | float + elif _type == 'boolean': + instance_type = bool + elif _type == 'float': + instance_type = float | int + elif _type == 'dict': + instance_type = dict + elif _type == 'array': + instance_type = list + elif _type == 'string': + instance_type = str + else: + maxkb_logger.error(_( + 'Field: {name} Type: {_type} Value: {value} Unsupported this type' + ).format(name=desc, _type=_type, value=value)) + return if not isinstance(value, instance_type): raise Exception(_( 'Field: {name} Type: {_type} Value: {value} Type error' ).format(name=desc, _type=_type, value=value)) - return value def get_parameters(body_setting, request: Request):