libyang icon indicating copy to clipboard operation
libyang copied to clipboard

bug with positional predicate

Open choppsv1 opened this issue 1 year ago • 4 comments

I'm finding that if I do a:

		err = lyd_new_path2(NULL, ly_native_ctx, xpath, NULL, 0, 0,
				    LYD_NEW_PATH_UPDATE, NULL, trunk);

where xpath is a path that ends in a keyless list entry with a positional predicate (e.g., /foos/foo[2]) I get a new node back. This must be a bug b/c i'm starting from an empty tree and asking for the second node in a keyless list. It's returning a single list node with no siblings IOW /foos/foo[1].

choppsv1 avatar Jan 07 '25 01:01 choppsv1

FWIW same issue exists when foo is a leaf-list.

choppsv1 avatar Jan 07 '25 01:01 choppsv1

What exactly would you expect to happen in your use-case? The only unexpected (undocumented) behavior is that any invalid indices are always normalized to the closest valid index, in this case 2 -> 1. In other words, any index higher than the current number of instances causes a new instance to be created.

michalvasko avatar Jan 07 '25 11:01 michalvasko

I would expect the same thing as if I tried to query a missing element and it couldn't return it -- I would expect it to error. Returning "something close" seems really sub-optimal, it would be like me trying to create a string node and libyang truncating the string b/c it couldn't handle the larger value I gave it, and then returning that with a success indication.

choppsv1 avatar Jan 07 '25 20:01 choppsv1

The very first time someone complains about this but I have no issue with whichever functioning so an error should now be printed.

michalvasko avatar Jan 08 '25 08:01 michalvasko