marvin-zhao / pyang

Automatically exported from code.google.com/p/pyang
0 stars 0 forks source link

Deviation of not-supported produces an error "ValueError: list.index(x): x not in list" #115

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add a "deviate not-supported" statement for a leaf statement like running 
target for copy-config in ietf-netconf.yang:
    deviation /nc:copy-config/nc:input/nc:target/nc:config-target/nc:running {
        description
            "copy-config operation to running datastore is not supported.";
        deviate not-supported;
    }

2. Run pyang on the module containing the above deviation statement
3. pyang crashes with an error of "ValueError: list.index(x): x not in list"

What is the expected output? What do you see instead?
Expect pyang to validate this. Instead it crashes

What version of the product are you using? On what operating system?
Using pyang v 1.4.1 on Windows 7

Please provide any additional information below.
The bug is in the two statements in statements.py below:
       idx = t.parent.substmts.index(t) # Need to check if the node exists
       del t.parent.substmts[idx] # Need to delete only if idx is valid

I propose the following change:
        idx = t.parent.substmts.index(t) if t in t.parent.substmts else -1
        if(idx != -1):
            del t.parent.substmts[idx]

Original issue reported on code.google.com by madhava....@gmail.com on 24 Nov 2014 at 10:32

GoogleCodeExporter commented 9 years ago

Original comment by mbj4...@gmail.com on 27 Nov 2014 at 8:26

GoogleCodeExporter commented 9 years ago
The problem turned out to be deviation of a shorthand case node.

This bug has now been fixed.

Original comment by mbj4...@gmail.com on 28 Nov 2014 at 7:36