data tree CHANGE remove implicit presence containers
Seems they cause more problems that they solve.
Consequently, there will be exceptions to RFC
7950 conformance. If a NP container has must
or when that evaluate to false, they will not
be present in the data tree nor for XPath
evaluation.
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index a0cb0eb..462bfb2 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -2514,31 +2514,8 @@
LY_ERR ret = LY_SUCCESS;
if (cont_p->presence) {
- /* explicit presence */
- cont->flags |= LYS_PRESENCE | LYS_SET_PRESENCE;
- } else if (cont_p->musts) {
- /* container with a must condition */
- LOGWRN(ctx->ctx, "Container \"%s\" changed to presence because it has a meaning from its \"must\" condition.",
- cont_p->name);
+ /* presence container */
cont->flags |= LYS_PRESENCE;
- } else if (cont_p->when) {
- /* container with a when condition */
- LOGWRN(ctx->ctx, "Container \"%s\" changed to presence because it has a meaning from its \"when\" condition.",
- cont_p->name);
- cont->flags |= LYS_PRESENCE;
- } else if (cont_p->parent) {
- if (cont_p->parent->nodetype == LYS_CHOICE) {
- /* container is an implicit case, so its existence decides the existence of the whole case */
- LOGWRN(ctx->ctx, "Container \"%s\" changed to presence because it has a meaning as a case of choice \"%s\".",
- cont_p->name, cont_p->parent->name);
- cont->flags |= LYS_PRESENCE;
- } else if ((cont_p->parent->nodetype == LYS_CASE) &&
- (((struct lysp_node_case *)cont_p->parent)->child == pnode) && !cont_p->next) {
- /* container is the only node in a case, so its existence decides the existence of the whole case */
- LOGWRN(ctx->ctx, "Container \"%s\" changed to presence because it has a meaning as a case of choice \"%s\".",
- cont_p->name, cont_p->parent->name);
- cont->flags |= LYS_PRESENCE;
- }
}
/* more cases when the container has meaning but is kept NP for convenience:
diff --git a/src/tree_data.c b/src/tree_data.c
index 6a1235c..16436fe 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1656,9 +1656,10 @@
node->flags = LYD_DEFAULT | (lysc_node_when(node->schema) ? LYD_WHEN_TRUE : 0);
lyd_insert_node(parent, first, node);
- /* cannot be a NP container with when */
- assert(!lysc_node_when(iter));
-
+ if (lysc_node_when(iter) && node_when) {
+ /* remember to resolve when */
+ LY_CHECK_RET(ly_set_add(node_when, node, 1, NULL));
+ }
if (diff) {
/* add into diff */
LY_CHECK_RET(lyd_val_diff_add(node, LYD_DIFF_OP_CREATE, diff));
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 47307c9..7e25fb7 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -838,7 +838,6 @@
* 10 LYS_SET_DFLT | | |x|x| | |x| | | | | | | |
* LYS_IS_ENUM | | | | | | | | | | | | |x| |
* LYS_KEYLESS | | | | |x| | | | | | | | | |
- * LYS_SET_PRESENCE |x| | | | | | | | | | | | | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* 11 LYS_SET_UNITS | | |x|x| | | | | | | | | | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -912,7 +911,6 @@
with default statement mandatory. In case the default leaf value is taken from type, it is thrown
away when it is refined to be mandatory node. Similarly it is used for deviations to distinguish
between own default or the default values taken from the type. */
-#define LYS_SET_PRESENCE 0x0200 /**< flag to know if container presence property was set explicitly */
#define LYS_SET_UNITS 0x0400 /**< flag to know if the leaf's/leaflist's units are their own (flag set) or it is taken from the type. */
#define LYS_SET_CONFIG 0x0800 /**< flag to know if the config property was set explicitly (flag set) or it is inherited. */
diff --git a/tests/utests/data/test_parser_json.c b/tests/utests/data/test_parser_json.c
index 02a2661..9b7cc07 100644
--- a/tests/utests/data/test_parser_json.c
+++ b/tests/utests/data/test_parser_json.c
@@ -326,7 +326,7 @@
CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
assert_non_null(tree);
tree = tree->next;
- CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE | LYS_SET_PRESENCE, 1, "cp",
+ CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
1, LYS_CONTAINER, 0, 0, NULL, 0);
CHECK_LYD_META(tree->meta, 1, "hint", 0, 1, INT8, "1", 1);
assert_null(tree->meta->next);
@@ -355,7 +355,7 @@
CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
assert_non_null(tree);
tree = tree->next;
- CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE | LYS_SET_PRESENCE, 1, "cp",
+ CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
1, LYS_CONTAINER, 0, 0, NULL, 0);
cont = (struct lyd_node_inner *)tree;
assert_false(cont->flags & LYD_DEFAULT);
@@ -454,7 +454,7 @@
0, LYS_ANYXML, 1, 0, NULL, 0);
node = ((struct lyd_node_any *)node)->value.tree;
- CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE | LYS_SET_PRESENCE, 1, "cp",
+ CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
1, LYS_CONTAINER, 0, 0, NULL, 0);
node = lyd_child(node);
/* z has no value */
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index cfff101..3d26002 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -227,7 +227,7 @@
CHECK_PARSE_LYD("<cp xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree);
assert_non_null(tree);
tree = tree->next;
- CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE | LYS_SET_PRESENCE, 1, "cp",
+ CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
1, LYS_CONTAINER, 0, 0, NULL, 0);
cont = (struct lyd_node_inner *)tree;
assert_false(cont->flags & LYD_DEFAULT);
@@ -341,7 +341,7 @@
CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0);
node = ((struct lyd_node_any *)node)->value.tree;
- CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE | LYS_SET_PRESENCE, 1, "cp",
+ CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
1, LYS_CONTAINER, 0, 0, NULL, 0);
node = lyd_child(node);
@@ -537,7 +537,7 @@
CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0);
node = ((struct lyd_node_any *)node)->value.tree;
- CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE | LYS_SET_PRESENCE, 1, "cp",
+ CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
1, LYS_CONTAINER, 0, 0, NULL, 0);
node = lyd_child(node);