[YANGTOOLS-1545] Min/max-elements are not enforced for wrapped elements in container Created: 02/Oct/23  Updated: 06/Oct/23

Status: Open
Project: yangtools
Component/s: None
Affects Version/s: 11.0.2
Fix Version/s: None

Type: Bug Priority: Medium
Reporter: Peter Suna Assignee: Ivan Hrasko
Resolution: Unresolved Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screenshot 2023-10-02 181339.png     PNG File Screenshot 2023-10-02 181427.png     PNG File Screenshot 2023-10-02 181444.png    

 Description   

Currently, it is possible to create a list/leaf-list with min-elements and max-element violations if those elements are wrapped with a container in the payload.

For example in this model:

module test-container-childs {
    namespace "http://example.com/test/container/child";
    prefix "tcc";
    revision 2023-09-28;

    container root-container {
        container nested-container {
            list mandatory-list {
                min-elements 1;
                max-elements 3;
                key id;
                leaf id {
                    type uint32;
                }
            }
        }
    }
}

 

It is allowed to create 0 list resources or more than 3, if the list `mandatory-list` is wrapped with "nested-container" in the payload:

{
    "nested-container": {
        "mandatory-list": []
    }
}

The same issue is present for the leaf-list element.

 

This issue was already reported before, and resolved:
https://jira.opendaylight.org/browse/YANGTOOLS-776



 Comments   
Comment by Robert Varga [ 03/Oct/23 ]

So "create" as in normalized node structure?
Or "create" as in the contents of DataTree?

Comment by Peter Suna [ 04/Oct/23 ]

It is possible to write into the task model using the method.
SnapshotBackedWriteTransaction.write(path, normalizedNode)
Data:
path -> /(http://example.com/test/container/child?revision=2023-09-28)root-container/nested-container
normalizedNode ->

ImmutableContainerNode{
  name=(http://example.com/test/container/child?revision=2023-09-28)nested-container,
  body=[
    ImmutableMapNode{
      name=(http://example.com/test/container/child?revision=2023-09-28)mandatory-list,
      body=[
        ImmutableMapEntryNode{
          name=(http://example.com/test/container/child?revision=2023-09-28)mandatory-list[{(http://example.com/test/container/child?revision=2023-09-28)id=1}],
          body=[
            ImmutableLeafNode{
              name=(http://example.com/test/container/child?revision=2023-09-28)id,
              body=1
            }
          ]
        },
        ImmutableMapEntryNode{
          name=(http://example.com/test/container/child?revision=2023-09-28)mandatory-list[{(http://example.com/test/container/child?revision=2023-09-28)id=2}],
          body=[
            ImmutableLeafNode{
              name=(http://example.com/test/container/child?revision=2023-09-28)id,
              body=2
            }
          ]
        },
        ImmutableMapEntryNode{
          name=(http://example.com/test/container/child?revision=2023-09-28)mandatory-list[{(http://example.com/test/container/child?revision=2023-09-28)id=3}],
          body=[
            ImmutableLeafNode{
              name=(http://example.com/test/container/child?revision=2023-09-28)id,
              body=3
            }
          ]
        },
        ImmutableMapEntryNode{
          name=(http://example.com/test/container/child?revision=2023-09-28)mandatory-list[{(http://example.com/test/container/child?revision=2023-09-28)id=4}],
          body=[
            ImmutableLeafNode{
              name=(http://example.com/test/container/child?revision=2023-09-28)id,
              body=4
            }
          ]
        }
      ]
    }
  ]
} 
Generated at Wed Feb 07 20:56:28 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.