data tree BUGFIX opaq node handling
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 4e85ebe..cb2cb1f 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -57,7 +57,7 @@
     if (children) {
         child = *children;
         if (options & LYD_CHILDREN_SKIP_KEYS) {
-            while (child && (child->schema->flags & LYS_KEY)) {
+            while (child && child->schema && (child->schema->flags & LYS_KEY)) {
                 child = child->next;
             }
         }