fix(ApplyDeviate): replace Exts on deviate replace, not append#4
Merged
Conversation
DeviationReplace was incorrectly appending extensions to the existing
slice instead of replacing them. The Default field already handles this
distinction correctly; apply the same pattern to Exts:
DeviationAdd -> append(deviatedNode.Exts, devSpec.Exts...)
DeviationReplace -> append([]*Statement{}, devSpec.Exts...)
Add a test case that verifies a pre-existing extension is discarded
when deviate replace supplies a different one.
Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Jun 10, 2026
This was referenced Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
ApplyDeviatenow copies extension statements (Exts) fromdeviate addanddeviate replacesubstatements onto the deviated targetEntry. Previously that propagation was missing entirely, so extensions declared inside a deviation (for examplesdcio-ext:sensitivein a device-profile overlay) never appeared on the parsed leaf entry.Motivation
RFC 7950 allows extension substatements under
deviate addanddeviate replace. The parser already attached them to the deviation-sideEntry(devSpec.Exts), butApplyDeviatenever merged them intodeviatedNode.Exts, so downstream consumers could not see them.SDCIO relies on this for marking sensitive leaves via deviations; see related work in sdc-protos#123, schema-server#244, and data-server#452.
What changed
Inside the existing
case DeviationAdd, DeviationReplacehandling (alongsideDefault,must, etc.), add explicitExtshandling mirroring theDefaultpattern:DeviationAdd:deviatedNode.Exts = append(deviatedNode.Exts, devSpec.Exts...)DeviationReplace:deviatedNode.Exts = append([]*Statement{}, devSpec.Exts...)— the target node's extension list becomes exactly the deviation's list (replace semantics), not a merge that keeps unrelated prior extensions from accumulating incorrectly when the spec intends a full substitution of the deviation-supplied set.Tests
deviate add propagates extensions onto target entry— extensions fromdeviate addreach the target leaf.deviate replace propagates extensions onto target entry— extensions fromdeviate replacereach the target leaf.deviate replace replaces existing extensions, does not accumulate— base leaf already hastag-ext:old-tag; overlaydeviate replacesuppliessdcio-ext:sensitive; result must not retain the old extension.Test plan
go test ./pkg/yang/...(or full module test as per repo CI)