The Python IDL code very closely mirrors the C IDL code, which uses
an hmap to store table rows. hmap code allows duplicate keys, while
IndexedRows, which is derived from DictBase does not.

The persistent UUID code can attempt to temporarily add a Row with
a duplicate UUID to table.rows, so IndexedRows is modified to
behave similarly to the C IDL's hmap implementation.

Fixes: 55b9507e6824 ("ovsdb-idl: Add the support to specify the uuid for row 
insert.")
Signed-off-by: Terry Wilson <twil...@redhat.com>
---
 python/ovs/db/custom_index.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/python/ovs/db/custom_index.py b/python/ovs/db/custom_index.py
index 587caf5e3..3fa03d3c9 100644
--- a/python/ovs/db/custom_index.py
+++ b/python/ovs/db/custom_index.py
@@ -90,14 +90,21 @@ class IndexedRows(DictBase, object):
         index = self.indexes[name] = MultiColumnIndex(name)
         return index
 
+    def __getitem__(self, key):
+        return self.data[key][-1]
+
     def __setitem__(self, key, item):
-        self.data[key] = item
+        try:
+            self.data[key].append(item)
+        except KeyError:
+            self.data[key] = [item]
         for index in self.indexes.values():
             index.add(item)
 
     def __delitem__(self, key):
-        val = self.data[key]
-        del self.data[key]
+        val = self.data[key].pop()
+        if len(self.data[key]) == 0:
+            del self.data[key]
         for index in self.indexes.values():
             index.remove(val)
 
-- 
2.34.3

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to