Revert the default instance number back to zero
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Mon, 25 Apr 2022 09:35:28 +0000 (12:35 +0300)
committerPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Tue, 10 May 2022 03:31:52 +0000 (06:31 +0300)
These types of cnfvars are much more ubiquitous in the code base
and cnfvars that could be instantiated in ranges of instance numbers
are typically instantiated via templates (cnfvar.templates) due to
their size complexity thus not really benefiting from a default -1
instance here.

src/cnfvar/model.py
src/cnfvar/store.py
test/cnfvar/test_model.py
test/cnfvar/test_store.py

index 242a9d3..827ff99 100644 (file)
@@ -246,7 +246,7 @@ class BaseCnf:
     _CHILD_TEMPLATE = "{lineno} {indent}({parent}) {name},{instance}: \"{value}\""
     _NEST_INDENT = "  "
 
-    def __init__(self, name, value, instance=-1, parent=None,
+    def __init__(self, name, value, instance=0, parent=None,
                  lineno=None, comment=None):
         """
         Create this instance.
index b0dcbcf..0ddb6db 100644 (file)
@@ -144,6 +144,9 @@ class CnfStore:
         This method can be used in child classes to use an alternative scheme,
         however for performance reasons the base API class uses the default and
         relies on the cnfvar backend to do this job.
+
+        ..todo:: This method compensates for limitations in production code that
+            might end up fixed up there deprecating our patching here.
         """
 
     def _do_commit(self, original_cnfs, arnied_cnfs, fix_problems=False):
index bbd2e63..3b2da00 100644 (file)
@@ -167,7 +167,7 @@ class TestModel(unittest.TestCase):
         user_cnf.value = "jane"
         user_cnf.children[1].value = "Jane"
         user_cnf.children.first_with_name("user_group_member_ref").value = "200"
-        user_cnf.add_children(("USER_GROUP_MEMBER_REF", 5))
+        user_cnf.add_children(("USER_GROUP_MEMBER_REF", 5, -1))
 
         # check correct types and equality
         self.assertEqual(user_cnf.instance, 2)
index b5612d3..1b48732 100644 (file)
@@ -143,7 +143,7 @@ class TestStore(unittest.TestCase):
 
         # test adding a reference from another cnfvar
         proxy_profile = store.query().with_name("PROXY_PROFILE").first_with_instance(2)
-        nic_0.add_child(("nic_lan_proxy_profile_ref"), proxy_profile.instance)
+        nic_0.add_child(("nic_lan_proxy_profile_ref"), proxy_profile.instance, -1)
 
         # testing changing the value
         nic_1.children.first(lambda c: c.name == "nic_comment") \