Skip to content

Commit 7c738d5

Browse files
committed
schema: use parsed object only if available
With libyang/sysrepo 4 and printed contexts, the parsed object can be null. Check the parsed object before using it to get the node type. Fixes: 0a4b09f ("cffi: allows to usage of libyang v4") Signed-off-by: Jeremie Leska <jeremie.leska@6wind.com>
1 parent 6c0727f commit 7c738d5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libyang/schema.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,8 @@ def units(self) -> Optional[str]:
15681568
return c2str(self.cdata_leaf.units)
15691569

15701570
def type(self) -> Type:
1571+
if not self.cdata_leaf_parsed:
1572+
return Type(self.context, self.cdata_leaf.type, None)
15711573
return Type(self.context, self.cdata_leaf.type, self.cdata_leaf_parsed.type)
15721574

15731575
def is_key(self) -> bool:
@@ -1599,6 +1601,8 @@ def units(self) -> Optional[str]:
15991601
return c2str(self.cdata_leaflist.units)
16001602

16011603
def type(self) -> Type:
1604+
if not self.cdata_leaflist_parsed:
1605+
return Type(self.context, self.cdata_leaflist.type, None)
16021606
return Type(
16031607
self.context, self.cdata_leaflist.type, self.cdata_leaflist_parsed.type
16041608
)

0 commit comments

Comments
 (0)