fix found items at dbmemory.set_list 83/8683/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 18 Mar 2020 07:31:54 +0000 (07:31 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 18 Mar 2020 07:31:54 +0000 (07:31 +0000)
Change-Id: I9c6c61cf79ca79bf0833e3aa3846c1d9d5ab3c8d
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_common/dbmemory.py

index c57f932..0c720e1 100644 (file)
@@ -375,12 +375,14 @@ class DbMemory(DbBase):
     def set_list(self, table, q_filter, update_dict, fail_on_empty=True, unset=None, pull=None, push=None):
         with self.lock:
             updated = 0
-            for i, db_item in self._find(table, self._format_filter(q_filter)):
+            found = 0
+            for _, db_item in self._find(table, self._format_filter(q_filter)):
+                found += 1
                 if self._update(db_item, update_dict, unset=unset, pull=pull, push=push):
                     updated += 1
-            if i == 0 and fail_on_empty:
-                raise DbException("Not found entry with _id='{}'".format(q_filter), HTTPStatus.NOT_FOUND)
-            return {"updated": updated} if i else None
+            if not found and fail_on_empty:
+                raise DbException("Not found entry with '{}'".format(q_filter), HTTPStatus.NOT_FOUND)
+            return {"updated": updated} if found else None
 
     def replace(self, table, _id, indata, fail_on_empty=True):
         """