-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: When there is a form node in the loop node, the loop data is lost #4214
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 |
---|---|---|
|
@@ -202,6 +202,9 @@ def get_node_params(n): | |
{**self.start_node.node_params, 'form_data': start_node_data}, self.start_node.workflow_params) | ||
if self.start_node.type == 'loop-node': | ||
loop_node_data = node_details.get('loop_node_data', {}) | ||
for k, v in node_details.get('loop_context_data').items(): | ||
if v is not None: | ||
self.start_node.context[k] = v | ||
self.start_node.context['loop_node_data'] = loop_node_data | ||
self.start_node.context['current_index'] = node_details.get('current_index') | ||
self.start_node.context['current_item'] = node_details.get('current_item') | ||
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 appears to be part of a function aimed at retrieving parameters for a node, including handling loop nodes. There are a few optimizations and improvements that can be made:
Here's an optimized version of the code incorporating some of these suggestions: def get_node_params(n):
start_node_data = node_details.get('start_node_data', {})
if n.start_node.type == 'loop-node':
loop_node_data = node_details.get('loop_node_data', {})
# Initialize context dictionary outside the loop for efficiency
updated_context = {}
for k, v in node_details.get('loop_context_data', {}).items():
if v is not None:
updated_context[k] = v
self.start_node.context.update(updated_context)
self.start_node.context['loop_node_data'] = loop_node_data
self.start_node.context['current_index'] = node_details.get('current_index', 0)
self.start_node.context['current_item'] = node_details.get('current_item')
return params_dict # Replace 'params_dict' with actual parameter dict logic This refactored version uses a dictionary |
||
|
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 provided code appears to be part of an artificial intelligence (AI) system designed to handle workflows with loop nodes and manage states. Here are some comments and suggestions for improving the code:
Comments: Add more detailed comments explaining what each method does, especially the
save_context
andget_details
methods.Variable Naming: Use descriptive variable names instead of abbreviations like
_
, which can make the code harder to read.Loop Context Data Logic: The logic for generating
loop_context_data
could potentially lead to unnecessary overhead if certain fields always have valid values. Make sure this logic is optimal based on your needs.Error Handling: Enhance error handling in critical sections such as saving context and fetching data.
Concurrency Considerations: If the workflow management involves concurrency, consider adding thread-safe operations to avoid data corruption.
Here's a revised version of the code with these considerations in mind:
These changes focus on clarity, readability, and maintainability while ensuring that the core functionality remains intact.