Open skarpe-github opened 3 months ago
I believe this is by design, see filter
option: https://github.com/robshakir/pyangbind/blob/master/docs/serialisation.md#serialising-data-into-json-
Though it does not seem to work for mode ietf, that is not clear to me if it is by design. The behavior for ietf in general is a bit suspect. That does feel more like a bug.
>>> print(pybindJSON.dumps(output, indent=4, mode="default", with_defaults=True, filter=False))
{
"example-container": {
"example-leaf": "default-value"
}
}
>>> print(pybindJSON.dumps(output, indent=4, mode="yang", with_defaults=True, filter=False))
{
"example-container": {
"example-leaf": "default-value"
}
}
>>> print(pybindJSON.dumps(output, indent=4, mode="ietf", with_defaults=True, filter=False))
{}
>>> print(pybindJSON.dumps(output, indent=4, mode="ietf", filter=False, select=False))
{
"test:example-container": {
"example-leaf": ""
}
}
>>>
>>> print(pybindJSON.dumps(output, indent=4, mode="ietf", filter=False))
{
"test:example-container": {
"example-leaf": ""
}
}
>>> print(pybindJSON.dumps(output, indent=4, mode="ietf", filter=False, select={'example-leaf': ''}))
{
"test:example-container": {
"example-leaf": ""
}
}
Very good catch with the filter
option, thank you @xavier-contreras !
Indeed, the ietf mode does not look right then...
The reason why the dumps method does not work for ietf mode in the example above seems to be here: https://github.com/robshakir/pyangbind/blob/35fb9a81670a900d6580f725ad624d82f591d736/pyangbind/lib/pybindJSON.py#L106 According to the class' docstring: https://github.com/robshakir/pyangbind/blob/35fb9a81670a900d6580f725ad624d82f591d736/pyangbind/lib/serialise.py#L292 the object is restructured to fit IETF requirements. Since the example schema does not follow IETF requirements, it makes sense that the dumps method does not work. Therefore, it is probably not a bug.
Yes I see, and if you follow your second link the next function also refers to this: https://github.com/robshakir/pyangbind/blob/35fb9a81670a900d6580f725ad624d82f591d736/pyangbind/lib/serialise.py#L392
Hi all,
not completely sure whether this is an issue or I am just expecting the wrong results....
When we set a default value in our example module:
...and then generate the Python module with pyangbind and load it:
... I would expect the default value to show up in any of these print commands:
But the output is an empty dictionary. When we use the get method (
print(test_obj.get())
), it shows the expected output{'example-container': {'example-leaf': 'default-value'}}
, but the pybindJSON.dumps does not. Is this a bug or on purpose?Tested with: Python 3.11.9 pyangbind==0.8.5
Any input would be much appreciated! Thank you!