data tree BUGFIX avoid duplicating list keys twice

Refs sysrepo/sysrepo#2277
diff --git a/src/tree_data.c b/src/tree_data.c
index 0aa1063..38dd22d 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -2814,8 +2814,22 @@
     }
 
     LY_LIST_FOR(node, orig) {
-        /* if there is no local parent, it will be inserted into first */
-        LY_CHECK_GOTO(rc = lyd_dup_r(orig, (struct lyd_node *)local_parent, &first, options, first ? NULL : &first), error);
+        if (lysc_is_key(orig->schema)) {
+            if (local_parent) {
+                /* the key must already exist in the parent */
+                rc = lyd_find_sibling_schema(local_parent->child, orig->schema, first ? NULL : &first);
+                LY_CHECK_ERR_GOTO(rc, LOGINT(LYD_CTX(node)), error);
+            } else {
+                assert(!(options & LYD_DUP_WITH_PARENTS));
+                /* duplicating a single key, okay, I suppose... */
+                rc = lyd_dup_r(orig, NULL, &first, options, first ? NULL : &first);
+                LY_CHECK_GOTO(rc, error);
+            }
+        } else {
+            /* if there is no local parent, it will be inserted into first */
+            rc = lyd_dup_r(orig, (struct lyd_node *)local_parent, &first, options, first ? NULL : &first);
+            LY_CHECK_GOTO(rc, error);
+        }
         if (nosiblings) {
             break;
         }