From bf6c5729597476199627c6750e8db3a92ce47c9c Mon Sep 17 00:00:00 2001 From: tierno Date: Thu, 12 Mar 2020 09:54:35 +0000 Subject: [PATCH] Minor fix at dbmemory db_set Change-Id: I6026eb35c4eb34670e2231c185a4ffd1aa33ac0a Signed-off-by: tierno --- osm_common/dbmemory.py | 3 +++ osm_common/tests/test_dbmemory.py | 1 + 2 files changed, 4 insertions(+) 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() -- 2.25.1