Skip to content

Commit

Permalink
[configdb] fix bug of leaving unwanted columns in a hash (sonic-net#23)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Wataru Ishida authored and lguohan committed Dec 5, 2017
1 parent c289190 commit b7861cc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/swsssdk/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b7861cc

Please sign in to comment.