Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/tools/serializers/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_query_set(self, workspace_manage, is_x_pack_ee):
if workspace_id is not None:
folder_query_set = folder_query_set.filter(workspace_id=workspace_id)
default_query_set = default_query_set.filter(workspace_id=workspace_id)
if folder_id is not None:
if folder_id is not None and folder_id != workspace_id:
folder_query_set = folder_query_set.filter(parent=folder_id)
default_query_set = default_query_set.filter(folder_id=folder_id)
if name is not None:
Expand All @@ -267,7 +267,6 @@ def get_query_set(self, workspace_manage, is_x_pack_ee):
tool_query_set = tool_query_set.filter(tool_type=tool_type)

query_set_dict = {
'folder_query_set': folder_query_set,
'tool_query_set': tool_query_set,
'default_query_set': default_query_set,
}
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 seems mostly correct and well-structured for filtering a queryset based on various criteria like workspace_id, folder_id, name, etc. However, there are a few minor improvements that can be made:

  1. Consistent Naming Convention: The names of variables (folder_query_set, tool_query_set, default_query_set) seem to follow a consistent naming scheme, which is good.

  2. Remove Redundancy in Logic: Although not strictly necessary due to the logic's correctness, it might be clearer to remove the redundant condition where folder_id equals workspace_id. This check does not affect the filtered results if you're checking both conditions together:

if folder_id is not None and folder_id != workspace_id:

This line means that the folder_id will only be included in the filter if it's different from the workspace_id.

  1. Ensure Proper Quoting Consistency: Make sure all string literals use appropriate quoting (single or double) consistently within the same block to avoid confusion and potential bugs due to mixing types.

Otherwise, the code looks clean and functional according to the current knowledge cutoff date. It provides flexibility in querying documents based on specific conditions related to their folders and tools.

Expand Down
Loading