-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Infinite loop increases maximum loop count limit #4088
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 |
|---|---|---|
|
|
@@ -85,8 +85,8 @@ export class WorkFlowInstance { | |
| const base_node_list = this.nodes.filter((item) => item.id === WorkflowType.Base) | ||
| return base_node_list[0] | ||
| } | ||
| extis_break_node() { | ||
| return this.nodes.some((item) => item.id === WorkflowType.LoopBreakNode) | ||
| exist_break_node() { | ||
| return this.nodes.some((item) => item.type === WorkflowType.LoopBreakNode) | ||
| } | ||
| /** | ||
| * 校验工作流 | ||
|
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 has a minor issue with the @@ -84,7 +84,7 @@ export class WorkFlowInstance {
const base_node_list = this.nodes.filter((item) => item.id === WorkflowType.Base);
return base_node_list[0];
}
- extis_break_node() {
+ exist_break_node() {
return this.nodes.some((item) => item.type === WorkflowType.LoopBreakNode);
}This change ensures that the correct property ( No other irregularities or major issues were identified in the rest of the code. If you have any further questions or need additional assistance, feel free to ask! |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ const validate = () => { | |
| const loop_node = props.nodeModel.graphModel.getNodeModelById(loop_node_id) | ||
| try { | ||
| workflow.is_loop_valid() | ||
| if (loop_node.properties.node_data.loop_type == 'LOOP' && !workflow.extis_break_node()) { | ||
| if (loop_node.properties.node_data.loop_type == 'LOOP' && !workflow.exist_break_node()) { | ||
| return Promise.reject({ | ||
| node: loop_node, | ||
| errMessage: t('views.applicationWorkflow.validate.loopNodeBreakNodeRequired'), | ||
|
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 you provided has a few issues:
Here's an optimized version of the function assuming those corrections are made: const validate = () => {
const loop_node = props.nodeModel.graphModel.getNodeModelById(loop_node_id);
try {
workflow.is_loop_valid();
// Check if the loop type is 'LOOP' and ensure a break node exists
if (loop_node.properties.node_data?.loop_type === 'Loop' && !workflow.exists_break_node()) {
return Promise.reject({
node: loop_node,
errMessage: 'loops must have at least one exit point'
});
}
} catch (error) {
console.error(error.message); // Log errors for debugging purposes
throw error; // Re-throw the error if validation fails
}
};This version includes:
|
||
|
|
||
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.
Here are some suggestions to improve the provided code:
Add
import typingat the top of your file, especially if it's using type annotations.Consider using f-strings instead of
.format()for string interpolation in Python 3.6+.If you're using Django templates, use
gettext_lazyinstead ofgettext.Make sure that the
CONFIG.get("MAX_LOOP_COUNT")handles any exceptions gracefully (e.g., returning a default value or raising an informative exception).If
node_params.get('child_node')is always non-empty, consider checking forNoneexplicitly before accessing attributes likeruntime_node_id.It might be beneficial to extract logic into separate functions with descriptive names, such as
_find_next_child,_check_max_iter, etc.These improvements will make the code cleaner and easier to maintain while being efficient.