Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: 修复函数库,非必填引用类型,不传值 执行报错 #1564 #1570

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

shaohuzhang1
Copy link
Contributor

fix: 修复函数库,非必填引用类型,不传值 执行报错 #1564

Copy link

f2c-ci-robot bot commented Nov 7, 2024

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/test-infra repository.

Copy link

f2c-ci-robot bot commented Nov 7, 2024

[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

@shaohuzhang1 shaohuzhang1 merged commit 739a20b into main Nov 7, 2024
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_funcation_lib branch November 7, 2024 07:47
@@ -62,6 +62,8 @@ def valid_reference_value(_type, value, name):
def convert_value(name: str, value, _type, is_required, source, node):
if not is_required and value is None:
return None
if not is_required and source == 'reference' and (value is None or len(value) == 0):
return None
if source == 'reference':
value = node.workflow_manage.get_reference_field(
value[0],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数的目的是将名称和值转换为不同的形式,并在必要的情况下进行处理。

我发现了两个问题:

  1. if source == 'reference':语句中添加了多余的括号,应该变为(source == 'reference').
  2. 如果值为空列表(即源引用的内容是空),则应返回None,没有改变其他情况下的逻辑。
  3. len(value)- 1 之间的连接使用错误:应用Python规则"数字与操作符之间必须有空白字符或一个逗号."

修复后的版本如下所示:

def convert_value(name: str, value, _type, is_required, source, node):
    if not is_required and value is None:
        return None
    elif source == "reference":
        # 这里需要根据具体情况进行修改以匹配实际需求
    else:
        raise ValueError("Invalid parameter values")

这解决了原始代码中的这些问题并提高了正确性。此外,现在可以在每个具体的场景下执行特定的操作来实现所需的行为,而不仅仅是通过单一条件覆盖所有可能性。希望这是您所寻求的答案!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants