[NETCONF-937] Error writing values with XML YANG Patch Created: 04/Jan/23  Updated: 24/Jan/23  Resolved: 24/Jan/23

Status: Resolved
Project: netconf
Component/s: restconf-nb
Affects Version/s: None
Fix Version/s: 5.0.1

Type: Bug Priority: High
Reporter: Peter Suna Assignee: Peter Suna
Resolution: Done Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File instance-identifier-patch-module@2015-11-21.yang    

 Description   

Invoking YANG Patch with XML payload (PATCH http://192.168.56.25:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=17830-sim-device/yang-ext:mount/instance-identifier-patch-module:patch-cont/my-list1=leaf1):

<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
<patch-id>test-patch</patch-id>
<comment>this is test patch</comment>
<edit>
    <edit-id>edit1</edit-id>
    <operation>replace</operation>
    <target>/my-leaf11</target>
    <value>
        <my-leaf11>my-leaf11 :: XML value</my-leaf11>
    </value>
</edit>
</yang-patch> 

Results in error and leaf value is not written:

{
  "errors": {
    "error": [
      {
        "error-tag": "malformed-message",
        "error-message": "Error parsing input: null",
        "error-type": "protocol"
      }
    ]
  }
}

Corresponding payload in JSON works.



 Comments   
Comment by Ivan Hrasko [ 05/Jan/23 ]

XmlPatchBodyReader contains redundant if condition which is not in JsonPatchBodyReader.

                if (schemaNode instanceof  ContainerSchemaNode || schemaNode instanceof ListSchemaNode) {
                    final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
                    final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
                    final XmlParserStream xmlParser = XmlParserStream.create(writer, inference);
                    xmlParser.traverse(new DOMSource(firstValueElement));
                    parsed = resultHolder.getResult();
                } else {
                    parsed = null;
                } 

This if condition causes that ChoiceSchemaNode, LeafListSchemaNode, etc. will not be parsed:
https://github.com/opendaylight/netconf/blob/master/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java#L144

JsonPatchBodyReader does not contain this condition before parsing patch value:
https://github.com/opendaylight/netconf/blob/master/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java#L259

https://github.com/opendaylight/netconf/blob/master/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java#L375

Therefore, this condition in XmlPatchBodyReader is redundant and should be removed.

Generated at Wed Feb 07 20:16:17 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.