Fix setting hash values
authorEd Bartosh <eduard.bartosh@intel.com>
Sun, 10 Aug 2014 21:14:47 +0000 (00:14 +0300)
committerLin A Yang <lin.a.yang@intel.com>
Wed, 13 Aug 2014 04:48:19 +0000 (07:48 +0300)
As hmset call doesn't remove old values this fuctionality
worked incorrectly and old values were not removed.

For example, removing 'PrereleaseDir' from repos.yaml and loading
it to the database was not removing this field in Redis.

Fixes: #2070

Change-Id: Ida42bd2a24a128b0f82f67bcc2a3b3905ff49920
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
common/backenddb.py

index 9690270..fee8cd3 100644 (file)
@@ -92,6 +92,11 @@ class Entity(object):
         key = "%s%s" % (self._prefix, key)
         if isinstance(value, dict):
             mvalue = deepcopy(value)
+            # delete fields which are not present in new value
+            for field in self._db.hgetall(key).keys():
+                if field not in mvalue:
+                    self._db.hdel(key, field)
+            # dump jsoned fields
             for field in self.jsoned:
                 mvalue[field] = json.dumps(value[field])
             self._db.hmset(key, mvalue)