Skip to content

Commit c8c480b

Browse files
alexmvmateuszmandera
authored andcommitted
mattermost: Handle duplicate dm-groups.
Observed in the wild, cause unknown. Partially fixes: zulip#24131. Co-authored-by: Mateusz Mandera <[email protected]>
1 parent 989d425 commit c8c480b

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

zerver/data_import/mattermost.py

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def convert_direct_message_group_data(
244244
for direct_message_group in direct_message_group_data:
245245
if len(direct_message_group["members"]) > 2:
246246
direct_message_group_members = frozenset(direct_message_group["members"])
247+
if direct_message_group_id_mapper.has(direct_message_group_members):
248+
logging.info("Duplicate direct message group found in the export data. Skipping.")
249+
continue
247250
direct_message_group_id = direct_message_group_id_mapper.get(
248251
direct_message_group_members
249252
)

zerver/tests/fixtures/mattermost_fixtures/direct_channel/export.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{"type":"post","post":{"team":"gryffindor","channel":"gryffindor-common-room","user":"harry","message":"Looks like this channel is empty","create_at":1553166567370,"reactions":[{"user":"ron","create_at":1553166584976,"emoji_name":"rocket"}],"replies":null,"attachments":[{"path":"20210622/teams/noteam/channels/mcrm7xee5bnpzn7u9ktsd91dwy/users/knq189b88fdxbdkeeasdynia4o/smaa5epsnp89tgjszzue1691ao/this is a file"}]}}
1414
{"type":"direct_channel","direct_channel":{"members":["ron","harry"],"favorited_by":null,"header":""}}
1515
{"type":"direct_channel","direct_channel":{"members":["ron","harry", "ginny"],"favorited_by":null,"header":""}}
16+
{"type":"direct_channel","direct_channel":{"members":["harry","ron", "ginny"],"favorited_by":null,"header":""}}
1617
{"type":"direct_post","direct_post":{"channel_members":["ron","harry"],"user":"ron","message":"hey harry","create_at":1566376137676,"flagged_by":null,"reactions":null,"replies":null,"attachments":[{"path":"20210622/teams/noteam/channels/mcrm7xee5bnpzn7u9ktsd91dwy/users/knq189b88fdxbdkeeasdynia4o/o3to4ezua3bajj31mzpkn96n5e/harry-ron.jpg"}]}}
1718
{"type":"direct_post","direct_post":{"channel_members":["ron","harry"],"user":"harry","message":"what's up","create_at":1566376318568,"flagged_by":null,"reactions":null,"replies":null,"attachments":null}}
1819
{"type":"direct_post","direct_post":{"channel_members":["ron","harry","ginny"],"user":"ginny","message":"Who is going to Hogsmeade this weekend?","create_at":1566376226493,"flagged_by":null,"reactions":null,"replies":null,"attachments":null}}

zerver/tests/test_mattermost_importer.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,16 @@ def test_convert_direct_message_group_data(self) -> None:
357357
team_name=team_name,
358358
)
359359

360-
zerver_huddle = convert_direct_message_group_data(
361-
direct_message_group_data=mattermost_data["direct_channel"],
362-
user_data_map=username_to_user,
363-
subscriber_handler=subscriber_handler,
364-
direct_message_group_id_mapper=direct_message_group_id_mapper,
365-
user_id_mapper=user_id_mapper,
366-
realm_id=3,
367-
team_name=team_name,
368-
)
360+
with self.assertLogs(level="INFO") as mock_log:
361+
zerver_huddle = convert_direct_message_group_data(
362+
direct_message_group_data=mattermost_data["direct_channel"],
363+
user_data_map=username_to_user,
364+
subscriber_handler=subscriber_handler,
365+
direct_message_group_id_mapper=direct_message_group_id_mapper,
366+
user_id_mapper=user_id_mapper,
367+
realm_id=3,
368+
team_name=team_name,
369+
)
369370

370371
self.assert_length(zerver_huddle, 1)
371372
direct_message_group_members = frozenset(mattermost_data["direct_channel"][1]["members"])
@@ -379,6 +380,10 @@ def test_convert_direct_message_group_data(self) -> None:
379380
),
380381
{1, 2, 3},
381382
)
383+
self.assertEqual(
384+
mock_log.output,
385+
["INFO:root:Duplicate direct message group found in the export data. Skipping."],
386+
)
382387

383388
def test_write_emoticon_data(self) -> None:
384389
fixture_file_name = self.fixture_file_name("export.json", "mattermost_fixtures")

0 commit comments

Comments
 (0)