@@ -3079,7 +3079,7 @@ LIBYANG_API_DEF LY_ERR
30793079lyd_diff_reverse_all (const struct lyd_node * src_diff , struct lyd_node * * diff )
30803080{
30813081 LY_ERR rc = LY_SUCCESS ;
3082- const struct lys_module * mod ;
3082+ const struct lys_module * mod = NULL ;
30833083 struct lyd_node * root , * elem , * iter ;
30843084 enum lyd_diff_op op ;
30853085
@@ -3093,14 +3093,16 @@ lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff)
30933093 /* duplicate diff */
30943094 LY_CHECK_RET (lyd_dup_siblings (src_diff , NULL , LYD_DUP_RECURSIVE | LYD_DUP_NO_LYDS , diff ));
30953095
3096- /* find module with metadata needed for later */
3097- mod = ly_ctx_get_module_latest (LYD_CTX (src_diff ), "yang" );
3098- LY_CHECK_ERR_GOTO (!mod , LOGINT (LYD_CTX (src_diff )); rc = LY_EINT , cleanup );
3099-
31003096 LY_LIST_FOR (* diff , root ) {
31013097 LYD_TREE_DFS_BEGIN (root , elem ) {
31023098 /* skip all keys */
31033099 if (!lysc_is_key (elem -> schema )) {
3100+ /* find module with metadata needed for later in the current node context */
3101+ if (!mod || (mod -> ctx != LYD_CTX (elem ))) {
3102+ mod = ly_ctx_get_module_latest (LYD_CTX (elem ), "yang" );
3103+ LY_CHECK_ERR_GOTO (!mod , LOGINT (LYD_CTX (src_diff )); rc = LY_EINT , cleanup );
3104+ }
3105+
31043106 /* find operation attribute, if any */
31053107 LY_CHECK_GOTO (rc = lyd_diff_get_op (elem , & op , NULL ), cleanup );
31063108
0 commit comments