Skip to content

Commit 076c0b0

Browse files
committed
schema: handle None parsed objects in type creation
In libyang4, when dealing with printed contexts, cdata_parsed is not set. Check it 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 076c0b0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libyang/schema.py

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

15701570
def type(self) -> Type:
1571-
return Type(self.context, self.cdata_leaf.type, self.cdata_leaf_parsed.type)
1571+
return Type(
1572+
self.context,
1573+
self.cdata_leaf.type,
1574+
self.cdata_leaf_parsed.type if self.cdata_leaf_parsed else None,
1575+
)
15721576

15731577
def is_key(self) -> bool:
15741578
if self.cdata_leaf.flags & lib.LYS_KEY:
@@ -1600,7 +1604,9 @@ def units(self) -> Optional[str]:
16001604

16011605
def type(self) -> Type:
16021606
return Type(
1603-
self.context, self.cdata_leaflist.type, self.cdata_leaflist_parsed.type
1607+
self.context,
1608+
self.cdata_leaflist.type,
1609+
self.cdata_leaflist_parsed.type if self.cdata_leaflist_parsed else None,
16041610
)
16051611

16061612
def defaults(self) -> Iterator[Union[None, bool, int, str, float]]:

0 commit comments

Comments
 (0)