Skip to content
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

When patching the {{}} placeholder in parameter, check for possible nil pointer #3714

Merged
merged 2 commits into from
May 9, 2020
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
25 changes: 18 additions & 7 deletions backend/src/apiserver/resource/resource_manager_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,25 @@ func OverrideParameterWithSystemDefault(workflow util.Workflow, apiRun *api.Run)
if servercommon.GetBoolConfigWithDefault(HasDefaultBucketEnvVar, false) {
patchedSlice := make([]wfv1.Parameter, 0)
for _, currentParam := range workflow.Spec.Arguments.Parameters {
desiredValue, err := PatchPipelineDefaultParameter(*currentParam.Value)
if err != nil {
return fmt.Errorf("failed to patch default value to pipeline. Error: %v", err)
if currentParam.Value != nil {
desiredValue, err := PatchPipelineDefaultParameter(*currentParam.Value)
if err != nil {
return fmt.Errorf("failed to patch default value to pipeline. Error: %v", err)
}
patchedSlice = append(patchedSlice, wfv1.Parameter{

Choose a reason for hiding this comment

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

Perhaps we can move this piece of logic out from if currentParam.Value != nil {...} else {...} because it's a common logic?

Copy link
Contributor Author

@jingzhang36 jingzhang36 May 9, 2020

Choose a reason for hiding this comment

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

A little problem here is that if I move out "patchedSlice = append...(desiredValue)" part of the if-else block, I'll still have to check that this append operation only happens when at least one of the Value and Default is non-nil (i.e., desiredValue is valid). In other words, when both Value and Default are nil, this append operation should be skipped. Therefore, I figure that moving it out seems adding more code somehow :) So I choose this one, which is a little bit redundant but arguably straightforward to read though.

Name: currentParam.Name,
Value: util.StringPointer(desiredValue),
})
} else if currentParam.Default != nil {
desiredValue, err := PatchPipelineDefaultParameter(*currentParam.Default)
if err != nil {
return fmt.Errorf("failed to patch default value to pipeline. Error: %v", err)
}
patchedSlice = append(patchedSlice, wfv1.Parameter{
Name: currentParam.Name,
Value: util.StringPointer(desiredValue),
})
}
patchedSlice = append(patchedSlice, wfv1.Parameter{
Name: currentParam.Name,
Value: util.StringPointer(desiredValue),
})
}
workflow.Spec.Arguments.Parameters = patchedSlice

Expand Down