# One question about the leaf default usage

**URL:** <https://dmap-community.ductus.global/t/one-question-about-the-leaf-default-usage/2504>\
**Category:** NETCONF\
**Created:** [June 4, 2019, 6:22am UTC](https://dmap-community.ductus.global/t/one-question-about-the-leaf-default-usage/2504 "2019-06-04T06:22:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darcyl](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@darcyl](https://dmap-community.ductus.global/u/darcyl)\
**Post date:** [June 4, 2019, 6:22am UTC](https://dmap-community.ductus.global/t/one-question-about-the-leaf-default-usage/2504/1 "2019-06-04T06:22:00Z")

</div>

Hi,  
I have a question about the leaf’s default usage, use the below exampe to show it.

1. The yang module:

```auto
# cat default.yang
module default{
  namespace "http://complex/default";
  prefix "default";
  container test1 {
     list test2{
        key id;
        leaf id{
          type uint8 {
              range "1..80";
          }
        }
        leaf type{
           type enumeration {
              enum "Act";
              enum "Term";
           }
           default "Act";
        }
        leaf trace{
           when "../type = 'Act'";
           type enumeration {
              enum "URI";
              enum "Number";
           }
           default "Number";
         }
         leaf name{
           must "not(../trace = 'URI')";
           type string;
        }
      }
    }
 } 

```

1. The XML file:

```auto
 # cat default.xml 
  <test1 xmlns="http://complex/default">
    <test2>
      <id>1</id>
      <type>Act</type>
      <trace>Number</trace>
      <name>abc</name>
    </test2>
    <test2>
      <id>2</id>
      <type>Term</type>
    </test2>
  </test1>

```

1. The edit-config result will report error.

```auto
# /root/lab-5/confd/bin/netconf-console --port=2022 --edit-config default.xml 
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <rpc-error>
    <error-type>application</error-type>
    <error-tag>unknown-element</error-tag>
    <error-severity>error</error-severity>
    <error-path xmlns:default="http://complex/default">
    /rpc/edit-config/config/default:test1/default:test2[default:id='2']/default:trace
  </error-path>
    <error-message xml:lang="en">/test1/test2[id='2']/trace: the 'when' expression "../type = 'Act'" failed</error-message>
    <error-info>
      <bad-element>trace</bad-element>
    </error-info>
  </rpc-error>
</rpc-reply>

```

1. My question is:  
In the RFC7950 [RFC 7950 - The YANG 1.1 Data Modeling Language](https://tools.ietf.org/html/rfc7950#section-7.6.1), the below description shows the default value won’t be used if the `when` condition is `false`. But the above error seems it still use the default value.

> 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.

**note:** Only the `leaf name` contains the `must` check which uses the `leaf trace` will trigger the `when` error(i.e.if I remove the `must` check in the `leaf name`, the above `when error` won’t be reported), I didn’t find in the RFC that the `default valude` is in use if the leaf is referred by other value.

---

<div class="post-metadata">

**Author:** ![mvf](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mvf/32/182_2.png) [@mvf](https://dmap-community.ductus.global/u/mvf)\
**Post date:** [June 4, 2019, 2:57pm UTC](https://dmap-community.ductus.global/t/one-question-about-the-leaf-default-usage/2504/2 "2019-06-04T14:57:31Z")

</div>

What ConfD release are you using? I tried this with several releases down to 6.3, in all of them the edit-config request passed without any errors.

---

<div class="post-metadata">

**Author:** ![darcyl](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@darcyl](https://dmap-community.ductus.global/u/darcyl)\
**Post date:** [June 5, 2019, 12:47am UTC](https://dmap-community.ductus.global/t/one-question-about-the-leaf-default-usage/2504/3 "2019-06-05T00:47:26Z")

</div>

Hi @mvf,  
My ConfD version is 6.2, maybe my release is too old.

```auto
# ./confd --version
6.2

```

---

<div class="post-metadata">

**Author:** ![mvf](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mvf/32/182_2.png) [@mvf](https://dmap-community.ductus.global/u/mvf)\
**Post date:** [June 5, 2019, 5:53am UTC](https://dmap-community.ductus.global/t/one-question-about-the-leaf-default-usage/2504/4 "2019-06-05T05:53:36Z")

</div>

Yes, I would think so. confd-6.2 was released 3 years ago, and 6 months younger confd-6.3 handles this correctly.
