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

Fix strategic merge patch $deleteFromPrimitiveList bug #110472

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,8 @@ func mergeSliceHandler(original, patch interface{}, schema LookupPatchMeta,
return nil, err
}

if fieldPatchStrategy == mergeDirective {
// Delete lists are handled the same way regardless of what the field's patch strategy is
if fieldPatchStrategy == mergeDirective || isDeleteList {
return mergeSlice(typedOriginal, typedPatch, schema, fieldPatchMergeKey, mergeOptions, isDeleteList)
} else {
return typedPatch, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,46 @@ $deleteFromPrimitiveList/mergingIntList:
Modified: []byte(`
foo:
- bar
`),
},
},
{
Description: "$deleteFromPrimitiveList should delete item from a list with merge patch strategy",
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
Original: []byte(`
mergingIntList:
- 1
- 2
- 3
`),
TwoWay: []byte(`
$deleteFromPrimitiveList/mergingIntList:
- 2
`),
Modified: []byte(`
mergingIntList:
- 1
- 3
`),
},
},
{
Description: "$deleteFromPrimitiveList should delete item from a list without merge patch strategy",
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
Original: []byte(`
nonMergingIntList:
- 1
- 2
- 3
`),
TwoWay: []byte(`
$deleteFromPrimitiveList/nonMergingIntList:
- 2
`),
Modified: []byte(`
nonMergingIntList:
- 1
- 3
`),
},
},
Expand Down