Skip to content

Commit b7861cc

Browse files
Wataru Ishidalguohan
authored andcommitted
[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 <ishida.wataru@lab.ntt.co.jp>
1 parent c289190 commit b7861cc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/swsssdk/configdb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ def set_entry(self, table, key, data):
157157
if data == None:
158158
client.delete(_hash)
159159
else:
160+
original = self.get_entry(table, key)
160161
client.hmset(_hash, self.__typed_to_raw(data))
162+
for k in [ k for k in original.keys() if k not in data.keys() ]:
163+
if type(original[k]) == list:
164+
k = k + '@'
165+
client.hdel(_hash, self.serialize_key(k))
161166

162167
def get_entry(self, table, key):
163168
"""Read a table entry from config db.

0 commit comments

Comments
 (0)