Closed ldacol closed 1 year ago
I observed that the issue appears due to present of two codec providers in the same function. The workaround would be separate decode and encode in two different functions or change the encoding type on-the-fly. Example:
def xml_to_json(xml: str) -> str:
codec = CodecService()
provider = CodecServiceProvider()
try:
provider.encoding = EncodingFormat.XML
model = codec.decode(provider, xml)
provider.encoding = EncodingFormat.JSON
json = codec.encode(provider, model)
return json
except Exception as err:
print(f"Exception: {err}")
return None
The result with this function implementation:
{
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
"instance": [
{
"instance-name": "default"
}
]
}
}
{
"Cisco-IOS-XR-snmp-agent-cfg:mib": {
"Cisco-IOS-XR-snmp-ifmib-cfg:interface-mib": {
"interface-alias-long": [null],
"interface-index-persistence": [null]
}
}
}
Issue tracker is ONLY used for reporting bugs. Please use the YDK Community for any support issues.
Expected Behavior
Current Behavior
CodecService fails to decode XML for Cisco XR Yang models when BGP and SNMP-IFMIB are present in the payload at the same time. Decode is successful when using either payload
Steps to Reproduce
Run the script below with the following payload referenced. The model is based on 7.6.2 but I believe it can be reproduced with any version.
Your Script
Logs
Enable logging and post the logs below
System Information
MacOs Ventura
(ydk_vne) ➜ GNSA python --version Python 3.8.15
(ydk_vne) ➜ GNSA pip freeze | grep ydk ydk @ file:///Users/ldacol/Code/GNSA/ydk-gen/gen-api/python/ydk/dist/ydk-0.8.6.3.tar.gz ydk-models-cisco-ios-xr-762 @ file:///Users/ldacol/Code/GNSA/ydk-gen/gen-api/python/cisco_ios_xr_762-bundle/dist/ydk-models-cisco-ios-xr-762-7.6.2.tar.gz ydk-models-ietf==0.1.6 ydk-models-juniper-junos-18-4R3 @ file:///Users/ldacol/Code/GNSA/ydk-gen/gen-api/python/juniper_junos_18_4R3-bundle/dist/ydk-models-juniper-junos-18-4R3-18.4.post3.tar.gz ydk-models-juniper-qfx-20-2R1 @ file:///Users/ldacol/Code/GNSA/ydk-gen/gen-api/python/juniper_qfx_20_2R1-bundle/dist/ydk-models-juniper-qfx-20-2R1-20.2.post1.tar.gz