-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: When the reference variable in the workflow is empty, take the value of None #3814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,13 +59,19 @@ def valid_reference_value(_type, value, name): | |
|
|
||
|
|
||
| def convert_value(name: str, value, _type, is_required, source, node): | ||
| if not is_required and (value is None or (isinstance(value, str) and len(value) == 0)): | ||
| if not is_required and (value is None or ((isinstance(value, str) or isinstance(value, list)) and len(value) == 0)): | ||
| return None | ||
| if source == 'reference': | ||
| value = node.workflow_manage.get_reference_field( | ||
| value[0], | ||
| value[1:]) | ||
|
|
||
| if value is None: | ||
| if not is_required: | ||
| return None | ||
| else: | ||
| raise Exception(_( | ||
| 'Field: {name} Type: {_type} is required' | ||
| ).format(name=name, _type=_type)) | ||
| value = valid_reference_value(_type, value, name) | ||
| if _type == 'int': | ||
| return int(value) | ||
|
|
@@ -81,15 +87,17 @@ def convert_value(name: str, value, _type, is_required, source, node): | |
| v = json.loads(value) | ||
| if isinstance(v, dict): | ||
| return v | ||
| raise Exception("类型错误") | ||
| raise Exception(_('type error')) | ||
| if _type == 'array': | ||
| v = json.loads(value) | ||
| if isinstance(v, list): | ||
| return v | ||
| raise Exception("类型错误") | ||
| raise Exception(_('type error')) | ||
| return value | ||
| except Exception as e: | ||
| raise Exception(f'字段:{name}类型:{_type}值:{value}类型错误') | ||
| raise Exception( | ||
| _('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type, | ||
| value=value)) | ||
|
|
||
|
|
||
| class BaseToolNodeNode(IToolNode): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code appears to be well-documented and follows best practices for variable naming and exception handling. However, there are a couple of minor suggestions for improvement:
Overall, the code looks clean and efficient while adhering to Python style guidelines. Any further improvements would depend on specific context and requirements. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -602,7 +602,10 @@ def get_reference_field(self, node_id: str, fields: List[str]): | |
| elif node_id == 'chat': | ||
| return INode.get_field(self.chat_context, fields) | ||
| else: | ||
| return self.get_node_by_id(node_id).get_reference_field(fields) | ||
| node = self.get_node_by_id(node_id) | ||
| if node: | ||
| return node.get_reference_field(fields) | ||
| return None | ||
|
|
||
| def get_workflow_content(self): | ||
| context = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet appears to be implementing methods for retrieving fields and workflow content from a node context. Here's a review with some comments on potential issues, optimizations, and improvements: Issues Detected:
Optimizations/Improvements:
Here’s an updated version of the function with these considerations: @@ -600,7 +600,11 @@ def get_reference_field(self, node_id: str, fields: List[str]):
elif node_id == 'chat':
return INode.get_field(self.chat_context, fields)
else:
- # Add null check before accessing get_reference_field
- return self.get_node_by_id(node_id).get_reference_field(fields)
+ node = self.get_node_by_id(node_id)
+ if node:
+ return node.get_reference_field(fields)
+ return None # Return None instead of an empty list
def get_workflow_content(self):
context = {Summary:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes you've made address potential issues related to handling empty values when converting references. Here's a concise summary of the main improvements:
ifcondition is now more comprehensive, checking for both empty strings and list types (None, string, list) to ensure all cases where an empty value should triggerNoneor exception handling are caught.This enhancement makes the function more robust and reliable for various input scenarios, especially when dealing with nested structures like lists.