Skip to content

Commit 9a626ef

Browse files
authored
fix: When the reference variable in the workflow is empty, take the value of None (#3814)
1 parent 319bd37 commit 9a626ef

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

apps/application/flow/step_node/tool_lib_node/impl/base_tool_lib_node.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ def valid_reference_value(_type, value, name):
7373

7474

7575
def convert_value(name: str, value, _type, is_required, source, node):
76-
if not is_required and (value is None or (isinstance(value, str) and len(value) == 0)):
77-
return None
78-
if not is_required and source == 'reference' and (value is None or len(value) == 0):
76+
if not is_required and (value is None or ((isinstance(value, str) or isinstance(value, list)) and len(value) == 0)):
7977
return None
8078
if source == 'reference':
8179
value = node.workflow_manage.get_reference_field(
8280
value[0],
8381
value[1:])
84-
82+
if value is None:
83+
if not is_required:
84+
return None
85+
else:
86+
raise Exception(_(
87+
'Field: {name} Type: {_type} is required'
88+
).format(name=name, _type=_type))
8589
value = valid_reference_value(_type, value, name)
8690
if _type == 'int':
8791
return int(value)

apps/application/flow/step_node/tool_node/impl/base_tool_node.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ def valid_reference_value(_type, value, name):
5959

6060

6161
def convert_value(name: str, value, _type, is_required, source, node):
62-
if not is_required and (value is None or (isinstance(value, str) and len(value) == 0)):
62+
if not is_required and (value is None or ((isinstance(value, str) or isinstance(value, list)) and len(value) == 0)):
6363
return None
6464
if source == 'reference':
6565
value = node.workflow_manage.get_reference_field(
6666
value[0],
6767
value[1:])
68-
68+
if value is None:
69+
if not is_required:
70+
return None
71+
else:
72+
raise Exception(_(
73+
'Field: {name} Type: {_type} is required'
74+
).format(name=name, _type=_type))
6975
value = valid_reference_value(_type, value, name)
7076
if _type == 'int':
7177
return int(value)
@@ -81,15 +87,17 @@ def convert_value(name: str, value, _type, is_required, source, node):
8187
v = json.loads(value)
8288
if isinstance(v, dict):
8389
return v
84-
raise Exception("类型错误")
90+
raise Exception(_('type error'))
8591
if _type == 'array':
8692
v = json.loads(value)
8793
if isinstance(v, list):
8894
return v
89-
raise Exception("类型错误")
95+
raise Exception(_('type error'))
9096
return value
9197
except Exception as e:
92-
raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误')
98+
raise Exception(
99+
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
100+
value=value))
93101

94102

95103
class BaseToolNodeNode(IToolNode):

apps/application/flow/workflow_manage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,10 @@ def get_reference_field(self, node_id: str, fields: List[str]):
602602
elif node_id == 'chat':
603603
return INode.get_field(self.chat_context, fields)
604604
else:
605-
return self.get_node_by_id(node_id).get_reference_field(fields)
605+
node = self.get_node_by_id(node_id)
606+
if node:
607+
return node.get_reference_field(fields)
608+
return None
606609

607610
def get_workflow_content(self):
608611
context = {

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"md-editor-v3": "^5.8.2",
3838
"mermaid": "^10.9.0",
3939
"moment": "^2.30.1",
40+
"nanoid": "^5.1.5",
4041
"nprogress": "^0.2.0",
4142
"pinia": "^3.0.1",
4243
"recorder-core": "^1.3.25011100",

ui/src/utils/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { nanoid } from 'nanoid'
12
/**
23
* 数字处理
34
*/
@@ -36,7 +37,7 @@ export function isFunction(fn: any) {
3637
随机id
3738
*/
3839
export const randomId = function () {
39-
return Math.floor(Math.random() * 10000) + ''
40+
return nanoid()
4041
}
4142

4243
/*

0 commit comments

Comments
 (0)