Repository: janehmueller/python-json-config

Issue:
Properly set required/optional access in Config Nodes that are created at a later point in time (e.g. upsert)
Pass the value of the member `strict_access` to children spawned at a later point in time

Discussion:

Patch:
diff --git a/python_json_config/__version__.py b/python_json_config/__version__.py
index a955fda..bc86c94 100644
--- a/python_json_config/__version__.py
+++ b/python_json_config/__version__.py
@@ -1,1 +1,1 @@
-__version__ = "1.2.1"
+__version__ = "1.2.2"
diff --git a/python_json_config/config_node.py b/python_json_config/config_node.py
index ce524d2..e11710d 100644
--- a/python_json_config/config_node.py
+++ b/python_json_config/config_node.py
@@ -122,12 +122,12 @@ class ConfigNode(object):
                 raise RuntimeError(f"Updating not existing key {self.__path_for_key(key)}. To insert non existing keys"
                                    f"set upsert=True.")
             if isinstance(value, dict):
-                self.__node_dict[key] = ConfigNode(value, path=self.__path + [key])
+                self.__node_dict[key] = ConfigNode(value, path=self.__path + [key], strict_access=self.strict_access)
             else:
                 self.__node_dict[key] = value
         else:
             if key not in self.__node_dict and upsert:
-                self.__node_dict[key] = ConfigNode({}, path=self.__path + [key])
+                self.__node_dict[key] = ConfigNode({}, path=self.__path + [key], strict_access=self.strict_access)
             elif key not in self.__node_dict:
                 raise RuntimeError(f"Updating not existing key {self.__path_for_key(key)}. To insert non existing keys"
                                    f"set upsert=True.")


Test patch:
diff --git a/tests/config_node/test_crud.py b/tests/config_node/test_crud.py
index 764e339..2df1fb9 100644
--- a/tests/config_node/test_crud.py
+++ b/tests/config_node/test_crud.py
@@ -136,6 +136,16 @@ def test_strict_access(config_dict):
         assert config.key2.nokey2 is None
 
 
+def test_access_options_in_new_nodes(config_dict):
+    config = ConfigNode(config_dict, strict_access=False)
+    assert config.key1 == 1
+    assert config.key10 is None
+
+    config.update("key10.key11", "testme", upsert=True)
+    assert config.key10.key11 == "testme"
+    assert config.key10.key12 is None
+
+
 def test_merge_env_variable():
     prefix = "PYTHONJSONCONFIG"
     variables = {f"{prefix}_TESTVALUE1": "bla", f"{prefix}_TESTVALUE2": "1"}