A list of some interesting edge cases in YANG and the FRR Northbound API.
A leafref
is a reference to a leaf in another part of the data tree.
Being leaves themselves, they can be used as the key for a list:
list mylist {
key "mykey";
leaf "mykey" {
type leafref {
path "../example-leaf";
}
}
leaf "example-leaf" {
type uint8;
}
}
Now we have an interesting situation. List keys are always mandatory, so
mykey
will always exist. mykey
is a leafref
, and leafref
by
default has require-instance true
, which means the referenced leaf is
required to exist in the data tree. However, example-leaf
is not marked
mandatory true
, which makes it optional by default. Now if we delete
example-leaf
, the resulting data tree is invalid as it violates the
require-instance true
constraint placed on it by the leafref
. So
effectively, any leaf
which is referenced by a leafref
where the
leafref
has require-instance true
and the leafref
itself is the
key of a list, implicitly has mandatory true
.