From: tierno Date: Thu, 12 Mar 2020 09:54:35 +0000 (+0000) Subject: Minor fix at dbmemory db_set X-Git-Tag: v7.1.0rc1~5 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F75%2F8675%2F2;p=osm%2Fcommon.git Minor fix at dbmemory db_set Change-Id: I6026eb35c4eb34670e2231c185a4ffd1aa33ac0a Signed-off-by: tierno --- diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py index bfc396d..c57f932 100644 --- a/osm_common/dbmemory.py +++ b/osm_common/dbmemory.py @@ -268,6 +268,9 @@ class DbMemory(DbBase): k_list = k.split(".") k_item_prev = k_list[0] populated = False + if k_item_prev not in db_nested and populate: + populated = True + db_nested[k_item_prev] = None for k_item in k_list[1:]: if isinstance(db_nested[k_item_prev], dict): if k_item not in db_nested[k_item_prev]: diff --git a/osm_common/tests/test_dbmemory.py b/osm_common/tests/test_dbmemory.py index d2fbf4e..cbc9715 100644 --- a/osm_common/tests/test_dbmemory.py +++ b/osm_common/tests/test_dbmemory.py @@ -711,6 +711,7 @@ class TestDbMemory(unittest.TestCase): ({"a": [[4]]}, {"a.0.0": "v"}, {"a": [["v"]]}, "set nested list"), ({"a": [[4]]}, {"a.0.2": "v"}, {"a": [[4, None, "v"]]}, "expand nested list"), ({"a": [[4]]}, {"a.2.2": "v"}, {"a": [[4], None, {"2": "v"}]}, "expand list and add number key"), + ({"a": None}, {"b.c": "v"}, {"a": None, "b": {"c": "v"}}, "expand at root"), ) db_men = DbMemory() db_men._find = Mock()