Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XPath expressions in 'when' statement not using the correct context #112

Open
eelcocramer opened this issue Jul 13, 2024 · 6 comments
Open

Comments

@eelcocramer
Copy link

eelcocramer commented Jul 13, 2024

I wanted to make this into a PR but cannot really find where this should be fixed. Any pointers that help me put this into a PR are appreciated!

I'm using the when statement in an action output:

output {
    leaf status {;
        type boolean;
        mandatory true;
    }
    leaf message {
        when "../status = 'false'";
        type string;
    }
}

According to yang linters the XPath ../status is correct but when I use this with freeconf I get an error in the restconf server's response: '..' not found in xpath

When I change the xpath query in the when statement to when "status = 'false'" the output of a restconf request is rendered correctly. However now the yang linters complain:

warning: node "component::status" is not found in "component::message"
@dhubler
Copy link
Collaborator

dhubler commented Jul 13, 2024 via email

@eelcocramer
Copy link
Author

eelcocramer commented Jul 13, 2024

An update.

I added a test case to reproduce this issue in my cloned repository. Test case can be found here.

The error is generated in the resolvePath function of xpath_impl. It can easily be fixed by changing the behaviour of meta.Find but I have the feeling that is not the correct way to fix this issue. I do believe the selection where resolvePath is called with, is not the right selection.

@eelcocramer
Copy link
Author

I tried running the test with a debugger to see if I could understand how it works but I'm lost at the yacc stuff.

@dhubler
Copy link
Collaborator

dhubler commented Jul 17, 2024 via email

@dhubler
Copy link
Collaborator

dhubler commented Jul 22, 2024

Is "../status" incorrect? parent of output would not have the "status" field.

@eelcocramer
Copy link
Author

eelcocramer commented Jul 22, 2024

But ../status refers to the parent of message and that does have the status field. Without the ../ (so when this library does work) pyang and other linters complain with a warning that the node status is not found in the node message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants