summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2023-03-21 22:23:08 +0000
committerDavid Robertson <davidr@element.io>2023-03-21 22:23:08 +0000
commite5afd0ab99847f3d3083d4522243f1c717c93ba0 (patch)
treeb25893d2e8b37b9ff633a3871cd5a14d0f84c196
parentUpdate 15295.bugfix (diff)
downloadsynapse-e5afd0ab99847f3d3083d4522243f1c717c93ba0.tar.xz
Make event objects unhashable
Generally speaking one should look up an event by its id. Otherwise
we'll fall back to `object.__hash__` (the instance's address, under
CPython) which is probably not what you want.

Noticed in #15240.
-rw-r--r--synapse/events/__init__.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index 91118a8d84..d3cec6412a 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -24,6 +24,7 @@ from typing import (
     Generic,
     Iterable,
     List,
+    NoReturn,
     Optional,
     Sequence,
     Tuple,
@@ -338,6 +339,9 @@ class EventBase(metaclass=abc.ABCMeta):
     type: DictProperty[str] = DictProperty("type")
     user_id: DictProperty[str] = DictProperty("sender")
 
+    def __hash__(self) -> NoReturn:
+        raise NotImplementedError()
+
     @property
     def event_id(self) -> str:
         raise NotImplementedError()