min-elements, max-elements and default deviations are incorrectly applied to all users of a grouping
If a node that originally came from a grouping is deviated with a min-elements, max-elements or default, all users of that grouping will have the same deviation.
For example, given the following module and deviation:
module test-one {
namespace "urn:test:one";
prefix "one";
grouping group-one {
list no-limit-list {
key "name";
leaf name {
type string;
}
}
leaf no-default {
type string;
}
}
container c1 {
uses group-one;
}
container c2 {
uses group-one;
}
}
module test-one-deviations {
namespace "urn:test:deviations:one";
prefix "one-dev";
import test-one { prefix one; }
deviation "/one:c1/one:no-limit-list" {
deviate add {
min-elements "1";
max-elements "5";
}
}
deviation "/one:c2/one:no-default" {
deviate add {
default "foo";
}
}
}
This results in:
-
/c1/no-limit-listand/c2/no-limit-listhave min-elements: 1, max-elements: 5 -
/c1/no-defaultand/c2/no-defaulthave a default value of "foo".
When a uses statement is processed it uses the partial deep copy here
[https://github.com/openconfig/goyang/blob/4bf67cb22e9d5dffb28029fad0e650303d669750/pkg/yang/entry.go#L1466]. The problem with this partial deep copy is that it does not deep copy the struct members ListAttr (*ListAttr) and Default ([]string) resulting in unwanted pointer aliasing. When the deviations are applied they change the ListAttr or Default members of the entry. Because of the pointer aliasing, the nodes for every user of the grouping are changed.
Given that this would be a breaking change, is it ok to proceed with fixing this? I have tested a fix and can post a pull-request soon.