Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Infinite loop increases maximum loop count limit

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 23, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 23, 2025

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit 4242c77 into v2 Sep 23, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_loop branch September 23, 2025 07:35
raise Exception(_('Exceeding the maximum number of cycles'))
"""
指定次数循环
@return:
Copy link
Contributor Author

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:

  1. Add import typing at the top of your file, especially if it's using type annotations.

  2. Consider using f-strings instead of .format() for string interpolation in Python 3.6+.

  3. If you're using Django templates, use gettext_lazy instead of gettext.

  4. Make sure that the CONFIG.get("MAX_LOOP_COUNT") handles any exceptions gracefully (e.g., returning a default value or raising an informative exception).

  5. If node_params.get('child_node') is always non-empty, consider checking for None explicitly before accessing attributes like runtime_node_id.

  6. 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)
}
/**
* 校验工作流
Copy link
Contributor Author

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'),
Copy link
Contributor Author

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:

  1. The variable exist_break_node should be capitalized as it is likely defined elsewhere and used with capitalization.

  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants