-
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
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| raise Exception(_('Exceeding the maximum number of cycles')) | ||
| """ | ||
| 指定次数循环 | ||
| @return: |
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.
| return this.nodes.some((item) => item.type === WorkflowType.LoopBreakNode) | ||
| } | ||
| /** | ||
| * 校验工作流 |
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 has a minor issue with the exist_break_node method. The comparison operation is incorrect; it should compare item.type rather than item.id. Here’s the corrected version of the method:
@@ -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 (type) is checked when looking for nodes to determine if there is a loop break node present in the workflow instance.
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!
| 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'), |
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 code you provided has a few issues:
-
The variable
exist_break_nodeshould be capitalized as it is likely defined elsewhere and used with capitalization. -
In the string
'views.applicationWorkflow.validate.loopNodeBreakNodeRequired', there might be incorrect characters that need to be corrected, such as single quotes instead of double ones if they are meant to be displayed directly in the user interface.
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:
- Corrected spelling and casing.
- Added proper object destructuring syntax for better readability.
- Included a comment explaining the purpose of the condition.
- Added logging for thrown errors.
- Ensured that the code is wrapped in a promise reject call only if the conditions fail.
fix: Infinite loop increases maximum loop count limit