Skip to content

Commit 877142b

Browse files
committed
schema: remove error after lyd_value_validate_dflt calls
libyang returns the realtype field when the store callback return code is LY_SUCCESS and LY_EINCOMPLETE. Don't raise an error when lyd_value_validate_dflt returns LY_EINCOMPLETE. The function can then use the val_type_cdata field. Add a leafref with a default value to yolo-nodetypes.yang. In this case, lyd_value_validate_dflt returns LY_EINCOMPLETE. In test_schema.py, check that the default function returns a correct str value. Link: https://github.com/CESNET/libyang/blob/master/src/tree_data_common.c#L682 Signed-off-by: Jeremie Leska <[email protected]>
1 parent 0a4b09f commit 877142b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

libyang/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ def default(self) -> Union[None, bool, int, str, float]:
15451545
val_type_cdata,
15461546
ffi.NULL,
15471547
)
1548-
if ret != lib.LY_SUCCESS:
1548+
if ret not in (lib.LY_SUCCESS, lib.LY_EINCOMPLETE):
15491549
raise self.context.error("Unable to get real type of default value")
15501550
self.cdata_default_realtype = Type(self.context, val_type_cdata[0], None)
15511551

@@ -1619,7 +1619,7 @@ def defaults(self) -> Iterator[Union[None, bool, int, str, float]]:
16191619
val_type_cdata,
16201620
ffi.NULL,
16211621
)
1622-
if ret != lib.LY_SUCCESS:
1622+
if ret not in (lib.LY_SUCCESS, lib.LY_EINCOMPLETE):
16231623
raise self.context.error("Unable to get real type of default value")
16241624
self.cdata_default_realtypes.append(
16251625
Type(self.context, val_type_cdata[0], None)

tests/test_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ def test_must(self):
732732
def test_leaf_default(self):
733733
leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/percentage"))
734734
self.assertIsInstance(leaf.default(), float)
735+
leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/leafref1"))
736+
self.assertIsInstance(leaf.default(), str)
737+
self.assertEqual("ASD", leaf.default())
735738

736739
def test_leaf_parsed(self):
737740
leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/percentage"))

tests/yang/yolo/yolo-nodetypes.yang

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ module yolo-nodetypes {
9393
leaf-list leaf-list2 {
9494
type string;
9595
}
96+
97+
leaf leafref1 {
98+
type leafref {
99+
path "/records/name";
100+
}
101+
default "ASD";
102+
}
96103
}
97104

98105
leaf test1 {

0 commit comments

Comments
 (0)