Ubuntu 22.04 and Python 3.10 preparation
[osm/common.git] / osm_common / dbmemory.py
index 9f8c571..e72db5b 100644 (file)
@@ -29,7 +29,7 @@ __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
 
 class DbMemory(DbBase):
     def __init__(self, logger_name="db", lock=False):
-        super().__init__(logger_namelock)
+        super().__init__(logger_name=logger_name, lock=lock)
         self.db = {}
 
     def db_connect(self, config):
@@ -126,26 +126,27 @@ class DbMemory(DbBase):
                 for content_item in content:
                     if key_list[key_next_index] == "ANYINDEX" and isinstance(v, dict):
                         matches = True
-                        for k2, v2 in target.items():
-                            k_new_list = k2.split(".")
-                            new_operator = "eq"
-                            if k_new_list[-1] in (
-                                "eq",
-                                "ne",
-                                "gt",
-                                "gte",
-                                "lt",
-                                "lte",
-                                "cont",
-                                "ncont",
-                                "neq",
-                            ):
-                                new_operator = k_new_list.pop()
-                            if not recursive_find(
-                                k_new_list, 0, content_item, new_operator, v2
-                            ):
-                                matches = False
-                                break
+                        if target:
+                            for k2, v2 in target.items():
+                                k_new_list = k2.split(".")
+                                new_operator = "eq"
+                                if k_new_list[-1] in (
+                                    "eq",
+                                    "ne",
+                                    "gt",
+                                    "gte",
+                                    "lt",
+                                    "lte",
+                                    "cont",
+                                    "ncont",
+                                    "neq",
+                                ):
+                                    new_operator = k_new_list.pop()
+                                if not recursive_find(
+                                    k_new_list, 0, content_item, new_operator, v2
+                                ):
+                                    matches = False
+                                    break
 
                     else:
                         matches = recursive_find(
@@ -398,16 +399,18 @@ class DbMemory(DbBase):
                         )
                         del dict_to_update[key_to_update]
                         updated = True
-                    except Exception:
-                        pass
+                    except Exception as unset_error:
+                        self.logger.error(f"{unset_error} occured while updating DB.")
             if pull:
                 for dot_k, v in pull.items():
                     try:
                         dict_to_update, key_to_update, _ = _iterate_keys(
                             dot_k, db_item, populate=False
                         )
-                    except Exception:
+                    except Exception as pull_error:
+                        self.logger.error(f"{pull_error} occured while updating DB.")
                         continue
+
                     if key_to_update not in dict_to_update:
                         continue
                     if not isinstance(dict_to_update[key_to_update], list):
@@ -430,8 +433,12 @@ class DbMemory(DbBase):
                         dict_to_update, key_to_update, _ = _iterate_keys(
                             dot_k, db_item, populate=False
                         )
-                    except Exception:
+                    except Exception as iterate_error:
+                        self.logger.error(
+                            f"{iterate_error} occured while iterating keys in db update."
+                        )
                         continue
+
                     if key_to_update not in dict_to_update:
                         continue
                     if not isinstance(dict_to_update[key_to_update], list):