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

Fix a bug which could lead to incorrect state #13278

Merged
merged 11 commits into from
Jul 15, 2022
10 changes: 5 additions & 5 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _gen_state_id() -> str:


class _StateCacheEntry:
__slots__ = ["state", "state_group", "prev_group", "delta_ids"]
__slots__ = ["_state", "state_group", "prev_group", "delta_ids"]

def __init__(
self,
Expand All @@ -97,7 +97,7 @@ def __init__(
raise Exception("Either state or state group must be not None")

# A map from (type, state_key) to event_id.
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
self.state = frozendict(state) if state is not None else None
self._state = frozendict(state) if state is not None else None

# the ID of a state group if one and only one is involved.
# otherwise, None otherwise?
Expand All @@ -115,8 +115,8 @@ async def get_state(
looking up the state group in the DB.
"""

if self.state is not None:
return self.state
if self._state is not None:
return self._state

assert self.state_group is not None

Expand All @@ -129,7 +129,7 @@ def __len__(self) -> int:
# cache eviction purposes. This is why if `self.state` is None it's fine
# to return 1.

return len(self.state) if self.state else 1
return len(self._state) if self._state else 1


class StateHandler:
Expand Down