data tree BUGFIX always set context
diff --git a/src/tree_data.c b/src/tree_data.c
index d2c1107..ffd3377 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -449,6 +449,9 @@
     uint32_t i, parse_opts, val_opts;
 
     LY_CHECK_ARG_RET(ctx, ctx || parent, in, data_type, parent || tree || op, LY_EINVAL);
+    if (!ctx) {
+        ctx = LYD_CTX(parent);
+    }
     if (tree) {
         *tree = NULL;
     }