fix: The data source tool cannot obtain the execution parameters#4517
fix: The data source tool cannot obtain the execution parameters#4517shaohuzhang1 merged 1 commit intov2from
Conversation
|
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. DetailsInstructions 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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| {**all_params, 'download_item': item}, | ||
| function_name='download') | ||
| file_bytes = result.get('file_bytes', []) | ||
| chunks = [] |
There was a problem hiding this comment.
The code looks mostly clean, but here are some minor suggestions for improvements:
-
The
workflow_paramsshould be imported from the correct module where it is defined instead of being referenced directly. -
There is no need to pass both
all_paramsandself.workflow_params.get('data_source')again when callingget_download_file_list, as you already have them inall_params. -
Similarly, when calling
download, you can remove the unnecessary line{**all_params, **self.workflow_params.get('data_source'), 'download_item': item}because all parameters are already provided inall_params. -
It's generally better to use dictionary unpacking with
|(union operator) instead of multiple assignment operations like{**all_params, ...}or similar.
Here is the improved version of the function:
def execute(self, tool_lib_id, input_field_list, **kwargs) -> NodeResult:
...
if self.node.properties.get('kind') == 'data-source':
exist = function_executor.exec_code(
f'{tool_lib.code}\ndef function_exist(function_name): return callable(globals().get(function_name))',
{'function_name': 'get_download_file_list'}
)
all_params.update({
'data_source_params': self.workflow_params.get('data_source', {})
})
if not exist:
# Handle case where get_download_file_list does not exist or other errors
...
download_files = []
files_data = function_executor.exec_code(
tool_lib.code,
all_params,
function_name='get_download_file_list'
)
for download_item in files_data:
file_content = function_executor.exec_code(
tool_lib.code,
{
**all_params,
'download_item': download_item
},
function_name='download'
)
# Process each chunk of the file content
chunks = []
# Your processing logic here...These changes make the code cleaner and more maintainable by reducing redundancy and improving readability.
fix: The data source tool cannot obtain the execution parameters