-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
…tup parameters - after importing, the tool should be disabled
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. |
[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 |
@@ -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) |
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 appears to be correct and well-written for its purpose. No major issues were found. Here are some minor improvements:
-
The
UploadedFileField
class definition is repeated with only a different docstring. Consider removing redundancy. -
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')
- Replace the line
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) |
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 couple of notable issues:
-
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 theTool
object constructor without validation or defaulting. -
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). -
Import Statements: There's an inconsistency between importing different serializers (
ToolModelSerializer
andToolExportModelSerializer
). Consider consolidating them into a single serializer based on the requirements.
Here are the specific suggestions:
-
Update the
to_tool
function to properly serialize tool data and validate theinput_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 )
-
Correct the usage of import statements:
from tools.serializers.tool import ToolSerializer
Consolidate both
ToolModelSerializer
andToolExportModelSerializer
into one class suitable for serialization needs. -
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.
fix: There is a tool node in the application - the tool node has startup parameters - after importing, the tool should be disabled