Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: The application export loop node cannot be used

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 27, 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 Oct 27, 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 f3bf9e2 into v2 Oct 27, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow_loop branch October 27, 2025 09:31
hand_node(n, update_tool_map)
return Application(id=uuid.uuid7(),
user_id=user_id,
name=application.get('name'),
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 appears to be part of an application that processes workflows. It includes a hand_node function to handle certain types of workflow nodes and updates them according to predefined rules. Additionally, it contains methods within the MKInstance class for querying resources and folders.

Review:

  1. Functionality Consistency: The hand_node function handles two specific types of nodes:

    • tool-lib-node: Updates the 'tool_lib_id'.
    • search-knowledge-node: Clears the 'knowledge_id_list'.
  2. Loop Node Handling: If the node type is "loop-node", the loop body also needs handling, but this was not done in the given code snippet. Consider adding logic to recurse through nested loops.

  3. Variable Naming: Use consistent variable names to improve readability. For example, consider renaming update_tool_map to tool_mapping.

  4. Error Handling: Add error handling around accessing dictionary items to prevent runtime errors, especially when dealing with optional keys (or ''). Consider using getattr or default parameter values.

  5. Performance Optimization:

    • Ensure there are no unnecessary list operations inside loops.
    • Avoid redundant method calls where possible.
  6. Documentation: Provide docstrings for all functions and classes to help other developers understand their purpose and usage.

Here's a revised version incorporating some suggested changes:

def hand_node(node, tool_mapping):
    """Handles specific node types."""
    if node.get('type') == 'tool-lib-node':
        tool_lib_id = node.get('properties', {}).get('node_data', {}).get('tool_lib_id', '')        
        # Update tool_lib_id using the mapping (if available)
        if tool_lib_id in tool_mapping:
            node['properties']['node_data'].update({'tool_lib_id': tool_mapping[tool_lib_id]})
    
    if node.get('type') == 'search-knowledge-node':
        node['properties']['node_data']['knowledge_id_list'] = []

class MKInstance:
    """Class responsible for managing instances of applications."""

    def __init__(self, application: dict, function_lib_list: List[dict], version: str, tool_list: List[dict]):
        self.application = application
        self.function_lib_list = function_lib_list
        self.version = version
        self.tool_list = tool_list

    def get_query_set(self, instance: Dict, workspace_manage: bool, is_x_pack_ee: bool) -> Tuple[QuerySet, QuerySet]:
        """Gets query sets based on instance details."""
        application_query_set = ...
        resource_and_folder_query_set = ...

        return {
            'application_query_set': application_query_set,
            'workspace_user_resource_permission_query_set': resource_and_folder_query_set
        }

    def to_tool(tool, workspace_id, user_id):
        ...  # Existing implementation

    def to_application(application, workspace_id, user_id, tool_mapping, folder_id=None) -> Application:
        """Converts application data to a new application instance."""
        work_flow = application.get('work_flow')

        for node in work_flow.get('nodes', []):
            hand_node(node, tool_mapping)

            # Handle nested.loop-body nodes
            loop_body_nodes = node.get('properties', {}).get('node_data', {}).get('loop_body', {}).get('nodes', [])
            for n in loop_body_nodes:
                hand_node(n, tool_mapping)

        return Application(id=uuid.uuid7(), 
                            user_id=user_id, 
                            name=application.get('name'), 
                            # Add other necessary fields here
                        )

This revision improves clarity, adds consistency, and addresses potential optimizations.

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