Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the apply_rec() API for bulk create operations according. #246

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[new_keys[idx]] = new_keys[idx]
andriy-kokhan marked this conversation as resolved.
Show resolved Hide resolved
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