Skip to content

Container node is added into Libyang data tree during parsing JSON file even if when status is false. #452

@corrollFang

Description

@corrollFang

----------base.yang--------------

module base{
    namespace "http://test-when/base";
    prefix "base";
    container c1
    {
        leaf flag
        {
            type boolean;
        }
    }
}

----------augment-when.yang-----------

module augment-when {
    namespace "http://test-when/augment-when";
    prefix "augment-when";
    import base {
        prefix "base";
    }
    augment "/base:c1" 
    {
        when "flag = 'true'";
        container aug-1
        {
            leaf xxx
            {
                type uint32;
            }
        }
    }
}

---JSON files---

{"base:c1":{"flag":false}}

After calling lyd_parse_fd(tmp_ctx->ctx, fd, LYD_JSON, LYD_OPT_TRUSTED | LYD_OPT_CONFIG), the returned data tree nodes are as below:

  <c1 xmlns="http://test-when/base">
    <flag>false</flag>
    <augment-when xmlns="http://test-when/augment-when"/>
  </c1>`

The container "augment-when" is added during lyd_wd_add_subtree() and will cause validation failed. I think it's not a good behavior, so i suggest to evaluate when expressions during adding default nodes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions