Skip to content

fix: There is a tool node in the application - the tool node has startup parameters - after importing, the tool should be disabled #3821

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

Merged
merged 1 commit into from
Aug 5, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: There is a tool node in the application - the tool node has startup parameters - after importing, the tool should be disabled

…tup parameters - after importing, the tool should be disabled
Copy link

f2c-ci-robot bot commented Aug 5, 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.

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.

Copy link

f2c-ci-robot bot commented Aug 5, 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.

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

@@ -376,7 +384,7 @@ def export(self):
self.is_valid()
id = self.data.get('id')
tool = QuerySet(Tool).filter(id=id).first()
tool_dict = ToolModelSerializer(tool).data
tool_dict = ToolExportModelSerializer(tool).data
mk_instance = ToolInstance(tool_dict, 'v2')
tool_pickle = pickle.dumps(mk_instance)
response = HttpResponse(content_type='text/plain', content=tool_pickle)
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 appears to be correct and well-written for its purpose. No major issues were found. Here are some minor improvements:

  1. The UploadedFileField class definition is repeated with only a different docstring. Consider removing redundancy.

  2. In the export method of the controller:

    • Replace the line response = HttpResponse(content_type='text/plain', content=tool_pickle) with:
      return Response(tool_pickle, content_type='text/plain')

These changes improve functionality by ensuring that the response format is correctly specified using Django REST Framework's Response object instead of plain HttpResponse. However, these small fixes should not affect the overall correctness or performance of the application. If you have specific requirements or additional tasks, feel free to ask!

@@ -682,7 +683,7 @@ def export(self, with_valid=True):
mk_instance = MKInstance(application_dict,
[],
'v2',
[ToolModelSerializer(tool).data for tool in
[ToolExportModelSerializer(tool).data for tool in
tool_list])
application_pickle = pickle.dumps(mk_instance)
response = HttpResponse(content_type='text/plain', content=application_pickle)
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 couple of notable issues:

  1. Serialization Logic: The to_tool function should be updated to handle the serialization logic correctly. Specifically, it currently passes all dictionary items directly as parameters in the Tool object constructor without validation or defaulting.

  2. Active Field Check: The condition for setting is_active does not align well with how active is typically defined (e.g., when there are no initialization fields).

  3. Import Statements: There's an inconsistency between importing different serializers (ToolModelSerializer and ToolExportModelSerializer). Consider consolidating them into a single serializer based on the requirements.

Here are the specific suggestions:

  1. Update the to_tool function to properly serialize tool data and validate the input_field_list:

         input_fields = None
         if 'input_field_list' in tool:
             try:
                 input_fields = json.loads(tool.get('input_field_list'))
             except ValueError:
                 raise Exception("Invalid JSON format for input_field_list")
    
         init_fields = None
         if 'init_field_list' in tool:
             try:
                 init_fields = json.loads(tool.get('init_field_list'))
             except ValueError:
                 raise Exception("Invalid JSON format for init_field_list")
    
         return Tool(
             id=tool.get('id'),
             user_id=user_id,
             name=tool.get('name'),
             code=tool.get('code'),
             template_id=tool.get('template_id'),
             input_field_list=input_fields,
             init_field_list=init_fields,
             is_active=False,  # Default to inactive unless initialized with field names
             scope=ToolScope.WORKSPACE,
             folder_id=workspace_id,
             workspace_id=workspace_id
         )
  2. Correct the usage of import statements:

    from tools.serializers.tool import ToolSerializer

    Consolidate both ToolModelSerializer and ToolExportModelSerializer into one class suitable for serialization needs.

  3. Review other parts of the export method to ensure consistent handling of tools during export.

These changes should help address the mentioned issues and improve the robustness and efficiency of the code.

@shaohuzhang1 shaohuzhang1 merged commit 4464573 into v2 Aug 5, 2025
3 of 4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_tool branch August 5, 2025 09:30
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.

1 participant