tree data BUGFIX forbid changing key node order
diff --git a/src/tree_data.c b/src/tree_data.c
index fe1b7d0..b1106ff 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -2771,6 +2771,10 @@
         LOGERR(LYD_CTX(sibling), LY_EINVAL, "Can be used only for user-ordered nodes.");
         return LY_EINVAL;
     }
+    if (lysc_is_key(sibling->schema)) {
+        LOGERR(LYD_CTX(sibling), LY_EINVAL, "Cannot insert before keys.");
+        return LY_EINVAL;
+    }
 
     lyd_unlink_tree(node);
     lyd_insert_before_node(sibling, node);
@@ -2791,6 +2795,10 @@
         LOGERR(LYD_CTX(sibling), LY_EINVAL, "Can be used only for user-ordered nodes.");
         return LY_EINVAL;
     }
+    if (sibling->next && lysc_is_key(sibling->next->schema)) {
+        LOGERR(LYD_CTX(sibling), LY_EINVAL, "Cannot insert before keys.");
+        return LY_EINVAL;
+    }
 
     lyd_unlink_tree(node);
     lyd_insert_after_node(sibling, node);