Skip to content

Commit 5f500a5

Browse files
authored
Fix the apply_rec() API for bulk create operations (#246)
Signed-off-by: IGordynskyi <[email protected]>
1 parent d9c0a1b commit 5f500a5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

common/sai.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,21 @@ def apply_rec(self, fname):
614614
# Update OIDs in the key
615615
key = self.__update_key(rec[0], key)
616616
# Convert into ["sai-object-type", "key"]
617-
key = key.split(":", 1)[1]
617+
if ":" in key:
618+
key = key.split(":", 1)[1]
618619

619-
if key.startswith("{"):
620+
if type(key) is dict or key.startswith("{"):
620621
key = json.loads(key)
621622
bulk_keys.append(key)
622623
bulk_attrs.append(attrs)
623624

624-
self.bulk_create(record[0][1], bulk_keys, bulk_attrs)
625+
if type(key) is dict or key.startswith("{"):
626+
self.bulk_create(record[0][1], bulk_keys, bulk_attrs)
627+
else:
628+
_, new_keys, _ = self.bulk_create(record[0][1], None, bulk_attrs, len(record)-1)
629+
for idx in range(0, len(new_keys)):
630+
if "oid:" in new_keys[idx]:
631+
self.rec2vid[record[idx + 1][0]] = new_keys[idx]
625632
for idx in range(len(bulk_keys)):
626633
self.create_rec_alias(record[0][1], bulk_attrs[idx], bulk_keys[idx])
627634

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

651659
if key.startswith("{"):
652660
key = json.loads(key)
@@ -669,7 +677,8 @@ def apply_rec(self, fname):
669677
# Update OIDs in the key
670678
key = self.__update_key(rec[0], key)
671679
# Convert into ["sai-object-type", "key"]
672-
key = key.split(":", 1)[1]
680+
if ":" in key:
681+
key = key.split(":", 1)[1]
673682

674683
if key.startswith("{"):
675684
key = json.loads(key)

0 commit comments

Comments
 (0)