Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 2a22a30

Browse files
author
David Robertson
committed
Fix mutation of @cached return value
Introduced in #12310, Synapse 1.57.0
1 parent 122a1ef commit 2a22a30

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

synapse/storage/databases/main/roommember.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
from typing import (
1717
TYPE_CHECKING,
18+
AbstractSet,
1819
Collection,
1920
Dict,
2021
FrozenSet,
@@ -418,10 +419,12 @@ async def get_rooms_for_local_user_where_membership_is(
418419
)
419420

420421
# Now we filter out forgotten and excluded rooms
421-
rooms_to_exclude: Set[str] = await self.get_forgotten_rooms_for_user(user_id)
422+
rooms_to_exclude = await self.get_forgotten_rooms_for_user(user_id)
422423

423424
if excluded_rooms is not None:
424-
rooms_to_exclude.update(set(excluded_rooms))
425+
# Take a copy to avoid mutating the in-cache set
426+
rooms_to_exclude = set(rooms_to_exclude)
427+
rooms_to_exclude.update(excluded_rooms)
425428

426429
return [room for room in rooms if room.room_id not in rooms_to_exclude]
427430

@@ -1175,7 +1178,7 @@ def f(txn: LoggingTransaction) -> int:
11751178
return count == 0
11761179

11771180
@cached()
1178-
async def get_forgotten_rooms_for_user(self, user_id: str) -> Set[str]:
1181+
async def get_forgotten_rooms_for_user(self, user_id: str) -> AbstractSet[str]:
11791182
"""Gets all rooms the user has forgotten.
11801183
11811184
Args:

0 commit comments

Comments
 (0)