You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Default whose when reads another conditional default depends on declaration order #2606
With the two leaves declared in the opposite order (b first, then c), the output is empty:
$ yanglint -f json -d all reversed/a.yang empty.json
{
}
c is never in use, since its condition is false(). The condition of b reads c, so b cannot be in use either, yet b is created with the first declaration order. Inside a container the same schema with a third leaf leaf test { type string; must "not(../b)"; } refuses <test>x</test> with Must condition "not(../b)" not satisfied. and accepts it in the reversed order.
Expected behaviour
The result does not depend on declaration order: c is evaluated first, its condition is false, so b's condition is false and neither default is in use.
RFC 7950, section 7.21.5:
If the XPath expression references any node that also has associated "when" statements, those "when" expressions MUST be evaluated first.
Section 7.6.1:
Note that if the leaf or any of its ancestors has a "when" condition or "if-feature" expression that evaluates to "false", then the default value is not in use.
Where it seems to come from
lyd_new_implicit_r() in tree_data_new.c creates default nodes with LYD_WHEN_TRUE already set. moveto_node_check() in xpath.c returns LY_EINCOMPLETE only for a node with neither LYD_WHEN_TRUE nor LYD_WHEN_FALSE, so when b's condition is evaluated before c's, c is read as existing instead of the evaluation being deferred. The order of the node_when set then decides the outcome.
Why it matters
Reordering leaves in a module, which should have no effect on data, changes which defaults exist and therefore whether data are valid.
Activity
validation BUGFIX order-independent when evaluation
michalvasko commentedon Nov 4, 2026
Was a bit trickier to fix but should now work reliably.