Skip to content

Commit

Permalink
fix(mockgun): ignore duplicate entities when multi_entity_update_mode…
Browse files Browse the repository at this point in the history
… is "add"
  • Loading branch information
slingshotvfx committed Aug 26, 2024
1 parent aaed90e commit 3dad90e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion shotgun_api3/lib/mockgun/mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,10 @@ def _update_row(self, entity_type, row, data, multi_entity_update_modes=None):
update_mode = multi_entity_update_modes.get(field, "set") if multi_entity_update_modes else "set"

if update_mode == "add":
row[field] += [{"type": item["type"], "id": item["id"]} for item in data[field]]
existing_ids = [item["id"] for item in row[field]]
for item in data[field]:
if item["id"] not in existing_ids:
row[field].append({"type": item["type"], "id": item["id"]})
elif update_mode == "remove":
row[field] = [
item
Expand Down
3 changes: 2 additions & 1 deletion tests/test_mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ def test_update_add(self):
"""
Ensures that "add" multi_entity_update_mode works.
"""
# _version2 already exists on the playlist and should not be duplicated
self._mockgun.update(
"Playlist", self._add_playlist["id"], {"versions": [self._version3]},
"Playlist", self._add_playlist["id"], {"versions": [self._version2, self._version3]},
multi_entity_update_modes={"versions": "add"}
)

Expand Down

0 comments on commit 3dad90e

Please sign in to comment.