From b7861cc4ae872eb91fa5c5c114eff43cd9e44ade Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Tue, 5 Dec 2017 21:08:22 +0900 Subject: [PATCH] [configdb] fix bug of leaving unwanted columns in a hash (#23) Current implementation doesn't remove unwanted columes with set_entry like below. >>> set_entry('table', 'key', {'key1': 'value1', 'key2': 'value2'}) >>> set_entry('table', 'key', {'key1': 'value3'}) >>> get_entry('table', 'key') {'key1': 'value3', 'key2': 'value2'} This commit fix this bug. Signed-off-by: Wataru Ishida --- src/swsssdk/configdb.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/swsssdk/configdb.py b/src/swsssdk/configdb.py index 68082d7fa..394f43b29 100644 --- a/src/swsssdk/configdb.py +++ b/src/swsssdk/configdb.py @@ -157,7 +157,12 @@ def set_entry(self, table, key, data): if data == None: client.delete(_hash) else: + original = self.get_entry(table, key) client.hmset(_hash, self.__typed_to_raw(data)) + for k in [ k for k in original.keys() if k not in data.keys() ]: + if type(original[k]) == list: + k = k + '@' + client.hdel(_hash, self.serialize_key(k)) def get_entry(self, table, key): """Read a table entry from config db.