Lately pyang --ietf has been crashing when parsing one of our larger YANG models. After some troubleshooting, I have isolated the issue to a small block and created a minimal example:
module inventory {
yang-version 1.1;
namespace "http://foo.com/inventory";
prefix inventory;
container inventory {
list interface-link {
list interface {
key "id";
leaf id {
must "deref(../id)/../role != 'access'" {
error-message "Oh no!";
}
type leafref {
path "deref(../type)/../id";
}
}
}
}
}
}
(Yes I realize the target of the leafrefs are now gone, but that is not relevant to the crash)
Save this as "example.yang", then run:
$ pyang --ietf example.yang
Output:
Traceback (most recent call last):
File "/home/tomas/.pyenv/versions/my-example-project/bin/pyang", line 580, in <module>
run()
File "/home/tomas/.pyenv/versions/my-example-project/bin/pyang", line 433, in run
ctx_validate_and_prune()
File "/home/tomas/.pyenv/versions/my-example-project/bin/pyang", line 429, in ctx_validate_and_prune
ctx.validate()
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/context.py", line 348, in validate
statements.validate_module(self, m)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 414, in validate_module
iterate(module, phase)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 402, in iterate
iterate(s, phase)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 402, in iterate
iterate(s, phase)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 402, in iterate
iterate(s, phase)
[Previous line repeated 1 more time]
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 406, in iterate
iterate(s, phase)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 371, in iterate
res = f(ctx, stmt)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 233, in <lambda>
('reference_2', 'must'):lambda ctx, s:v_reference_must(ctx, s),
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 2173, in v_reference_must
v_xpath(ctx, stmt)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/statements.py", line 2190, in v_xpath
xpath.v_xpath(ctx, stmt, node)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/xpath.py", line 85, in v_xpath
chk_xpath_expr(ctx, stmt.i_orig_module, stmt.pos, node, node, q, None)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/xpath.py", line 107, in chk_xpath_expr
chk_xpath_expr(ctx, mod, pos, initial, node, q[2], None)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/xpath.py", line 97, in chk_xpath_expr
chk_xpath_path(ctx, mod, pos, initial, node, q)
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/xpath.py", line 232, in chk_xpath_path
(rettype, tgt) = chk_xpath_function(ctx, mod, pos, initial,
File "/home/tomas/.pyenv/versions/3.8.6/envs/my-example-project/lib/python3.8/site-packages/pyang/xpath.py", line 206, in chk_xpath_function
not isinstance(type_.i_type_spec,
AttributeError: i_type_spec
The YANG model compiles successfully and works as expected, so it should not make pyang crash.
Lately
pyang --ietf
has been crashing when parsing one of our larger YANG models. After some troubleshooting, I have isolated the issue to a small block and created a minimal example:(Yes I realize the target of the leafrefs are now gone, but that is not relevant to the crash)
Save this as "example.yang", then run:
Output:
The YANG model compiles successfully and works as expected, so it should not make
pyang
crash.