CZ-NIC/yangson

prefix test is not defined in ('test', '')

Closed this issue · 5 comments

This issue appears when trying to augment to container from the same module where the augment is.
This issue appears only when there is at least one module imported.

YANGSON-VERSION: 1.3.59

JSON Module state when not importing:

{
  "ietf-yang-library:modules-state": {
    "module-set-id": "0",
    "module": [
      {
        "name": "test",
        "namespace": "test.com",
        "revision": "",
        "conformance-type": "implement"
      }
    ]
  }
}

JSON Module state when importing:

{
  "ietf-yang-library:modules-state": {
    "module-set-id": "0",
    "module": [
      {
        "name": "test",
        "namespace": "test.com",
        "revision": "",
        "conformance-type": "implement"
      },
      {
        "name": "test2",
        "namespace": "test2.com",
        "revision": "",
        "conformance-type": "implement"
      }
    ]
  }
}

First YANG file:

module test {

  yang-version "1.1";
  namespace "test.com";
  prefix test;

  import test2{ // Without this import everything seems to work. 
    prefix test2; // However I have to import this and many other modules in real project...
  }

  container main {
    leaf leaf1 {
      type string;
    }
  }

  augment /test:main { //Issue disappears when using augment /main (without test:) even when modules are imported
    leaf-list listofstrings {
      type string;
    }
  }
}

Second YANG file:

// Content of this module is simplified for better understanding...
module test2 {

  yang-version "1.1";
  namespace "test2.com";
  prefix test2;

  container main2 {
    leaf leaf2 {
      type string;
    }
  }
}

Both modules have the same namespace test.com, which is illegal. If you change the namespace of the test2 module to test2.com, then everything works fine.

Both modules have the same namespace test.com, which is illegal. If you change the namespace of the test2 module to test2.com, then everything works fine.

Thanks, for your reply. I changed namespace variable as you mentioned however it doesn't work either.

Console log (modules-state is auto-generated from module data):

{
  "ietf-yang-library:modules-state": {
    "module-set-id": "0",
    "module": [
      {
        "name": "test",
        "namespace": "test.com",
        "revision": "",
        "conformance-type": "implement"
      },
      {
        "name": "test2",
        "namespace": "test2.com",
        "revision": "",
        "conformance-type": "implement"
      }
    ]
  }
}
('test', '')
Traceback (most recent call last):
  File "/home/hjm02/PycharmProjects/yang_diff_wab/json_builder/__main__.py", line 52, in <module>
    dm = DataModel.from_file(b.json_file.name, tuple(paths))
  File "/home/hjm02/PycharmProjects/yang_diff_wab/yangdiff/libs/yangson/datamodel.py", line 59, in from_file
    return cls(yltxt, mod_path, description)
  File "/home/hjm02/PycharmProjects/yang_diff_wab/yangdiff/libs/yangson/datamodel.py", line 86, in __init__
    self._build_schema()
  File "/home/hjm02/PycharmProjects/yang_diff_wab/yangdiff/libs/yangson/datamodel.py", line 203, in _build_schema
    self.schema._augment_stmt(aug, sctx)
  File "/home/hjm02/PycharmProjects/yang_diff_wab/yangdiff/libs/yangson/schemanode.py", line 654, in _augment_stmt
    path = sctx.schema_data.sni2route(stmt.argument, sctx)
  File "/home/hjm02/PycharmProjects/yang_diff_wab/yangdiff/libs/yangson/schemadata.py", line 385, in sni2route
    res.append(self.translate_node_id(qn, sctx))
  File "/home/hjm02/PycharmProjects/yang_diff_wab/yangdiff/libs/yangson/schemadata.py", line 344, in translate_node_id
    raise UnknownPrefix(p, sctx.text_mid) from None
yangdiff.libs.yangson.exceptions.UnknownPrefix: prefix test is not defined in ('test', '')

I am not able to reproduce this:

(yangson) $ cat ylib.json 
{
  "ietf-yang-library:modules-state": {
    "module-set-id": "0",
    "module": [
      {
        "name": "test",
        "namespace": "test.com",
        "revision": "",
        "conformance-type": "implement"
      },
      {
        "name": "test2",
        "namespace": "test2.com",
        "revision": "",
        "conformance-type": "implement"
      }
    ]
  }
}

(yangson) $ cat test.yang 
module test {

  yang-version "1.1";
  namespace "test.com";
  prefix test;

  import test2{
    prefix test2;
  }

  container main {
    leaf leaf1 {
      type string;
    }
  }

  augment /test:main {
    leaf-list listofstrings {
      type string;
    }
  }
}

(yangson) $ cat test2.yang 
module test2 {

  yang-version "1.1";
  namespace "test2.com";
  prefix test2;

  container main2 {
    leaf leaf2 {
      type string;
    }
  }
}
(yangson) $ cat test.py
from yangson import DataModel

dm = DataModel.from_file("ylib.json")
(yangson) $ python test.py
(yangson) $

Can you perhaps try it with Yangson 1.3.65?

Can you perhaps try it with Yangson 1.3.65?

Thank you very much! It works with newer version.