Skip to content

Commit

Permalink
Fix the apply_rec() API for bulk create operations (#246)
Browse files Browse the repository at this point in the history
Signed-off-by: IGordynskyi <[email protected]>
  • Loading branch information
IGordynskyi authored Dec 19, 2024
1 parent d9c0a1b commit 5f500a5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions common/sai.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,21 @@ def apply_rec(self, fname):
# Update OIDs in the key
key = self.__update_key(rec[0], key)
# Convert into ["sai-object-type", "key"]
key = key.split(":", 1)[1]
if ":" in key:
key = key.split(":", 1)[1]

if key.startswith("{"):
if type(key) is dict or key.startswith("{"):
key = json.loads(key)
bulk_keys.append(key)
bulk_attrs.append(attrs)

self.bulk_create(record[0][1], bulk_keys, bulk_attrs)
if type(key) is dict or key.startswith("{"):
self.bulk_create(record[0][1], bulk_keys, bulk_attrs)
else:
_, new_keys, _ = self.bulk_create(record[0][1], None, bulk_attrs, len(record)-1)
for idx in range(0, len(new_keys)):
if "oid:" in new_keys[idx]:
self.rec2vid[record[idx + 1][0]] = new_keys[idx]
for idx in range(len(bulk_keys)):
self.create_rec_alias(record[0][1], bulk_attrs[idx], bulk_keys[idx])

Expand All @@ -646,7 +653,8 @@ def apply_rec(self, fname):
# Update OIDs in the key
key = self.__update_key(rec[0], key)
# Convert into ["sai-object-type", "key"]
key = key.split(":", 1)[1]
if ":" in key:
key = key.split(":", 1)[1]

if key.startswith("{"):
key = json.loads(key)
Expand All @@ -669,7 +677,8 @@ def apply_rec(self, fname):
# Update OIDs in the key
key = self.__update_key(rec[0], key)
# Convert into ["sai-object-type", "key"]
key = key.split(":", 1)[1]
if ":" in key:
key = key.split(":", 1)[1]

if key.startswith("{"):
key = json.loads(key)
Expand Down

0 comments on commit 5f500a5

Please sign in to comment.