diff --git a/libyang/schema.py b/libyang/schema.py index f104a87..e8bbe70 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -1545,7 +1545,7 @@ def default(self) -> Union[None, bool, int, str, float]: val_type_cdata, ffi.NULL, ) - if ret != lib.LY_SUCCESS: + if ret not in (lib.LY_SUCCESS, lib.LY_EINCOMPLETE): raise self.context.error("Unable to get real type of default value") self.cdata_default_realtype = Type(self.context, val_type_cdata[0], None) @@ -1619,7 +1619,7 @@ def defaults(self) -> Iterator[Union[None, bool, int, str, float]]: val_type_cdata, ffi.NULL, ) - if ret != lib.LY_SUCCESS: + if ret not in (lib.LY_SUCCESS, lib.LY_EINCOMPLETE): raise self.context.error("Unable to get real type of default value") self.cdata_default_realtypes.append( Type(self.context, val_type_cdata[0], None) diff --git a/tests/test_schema.py b/tests/test_schema.py index a1ca412..52a7af7 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -732,6 +732,9 @@ def test_must(self): def test_leaf_default(self): leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/percentage")) self.assertIsInstance(leaf.default(), float) + leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/leafref1")) + self.assertIsInstance(leaf.default(), str) + self.assertEqual("ASD", leaf.default()) def test_leaf_parsed(self): leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/percentage")) @@ -789,6 +792,9 @@ def test_leaflist_defaults(self): leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/integers")) for d in leaflist.defaults(): self.assertIsInstance(d, int) + leaflist3 = next(self.ctx.find_path("/yolo-nodetypes:conf/leaf-list3")) + for d in leaflist3.defaults(): + self.assertIsInstance(d, str) def test_leaf_list_min_max(self): leaflist1 = next(self.ctx.find_path("/yolo-nodetypes:conf/leaf-list1")) diff --git a/tests/yang/yolo/yolo-nodetypes.yang b/tests/yang/yolo/yolo-nodetypes.yang index 5b99475..9926b1a 100644 --- a/tests/yang/yolo/yolo-nodetypes.yang +++ b/tests/yang/yolo/yolo-nodetypes.yang @@ -93,6 +93,20 @@ module yolo-nodetypes { leaf-list leaf-list2 { type string; } + + leaf leafref1 { + type leafref { + path "/records/name"; + } + default "ASD"; + } + + leaf-list leaf-list3 { + type leafref { + path "/records/name"; + } + default "ASD"; + } } leaf test1 {