From 076c0b073cc7f9c0912ef9b854d34e4a3c6353a3 Mon Sep 17 00:00:00 2001 From: Jeremie Leska Date: Fri, 20 Feb 2026 15:26:30 +0100 Subject: [PATCH] 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: 0a4b09f461a3 ("cffi: allows to usage of libyang v4") Signed-off-by: Jeremie Leska --- libyang/schema.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libyang/schema.py b/libyang/schema.py index f7fda21..d3f5465 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -1568,7 +1568,11 @@ def units(self) -> Optional[str]: return c2str(self.cdata_leaf.units) def type(self) -> Type: - return Type(self.context, self.cdata_leaf.type, self.cdata_leaf_parsed.type) + return Type( + self.context, + self.cdata_leaf.type, + self.cdata_leaf_parsed.type if self.cdata_leaf_parsed else None, + ) def is_key(self) -> bool: if self.cdata_leaf.flags & lib.LYS_KEY: @@ -1600,7 +1604,9 @@ def units(self) -> Optional[str]: def type(self) -> Type: return Type( - self.context, self.cdata_leaflist.type, self.cdata_leaflist_parsed.type + self.context, + self.cdata_leaflist.type, + self.cdata_leaflist_parsed.type if self.cdata_leaflist_parsed else None, ) def defaults(self) -> Iterator[Union[None, bool, int, str, float]]: